是否可以限制SFSpeechRecognizer的词汇量?



我想使用iosSFSpeechRecognizer来识别一组封闭的单词和短语。有没有办法具体说明这些并消除所有其他可能性?我似乎找不到做这件事的方法。

您可以尝试使用SFSpeechAudioBufferRecognitionRequestcontextStrings属性来设置高优先级或设置一些不在词汇表中的单词。有关更多信息,请查看此处:https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/1649391-contextualstrings?language=objc

SFSpeechAudioBufferRecognitionRequest *recognitionRequest = [[SFSpeechAudioBufferRecognitionRequest alloc] init];
recognitionRequest.contextualStrings = @[@"Your specific word", @"short custom phrases that are unique to your app"];

我认为您不能限制SFSpeechRecognizer的词汇,但只有当您想要的单词被识别时,您才能启动操作。

当你得到你的输出时,你可以尝试这样的东西:

self.recognitionTask = speechRecognizer?.recognitionTask(with: recognitionRequest, resultHandler: { (result, error) in
if result == "Desired word one" {
// Do something
} else if result == "Desired word two" {
// Do something else
} else {
// Don't do anything
}
})

经过一些尝试和错误,最好的解决方案是将Mrsantateam和Giuseppe Garassino的答案混合在一起。

您可以首先指定应该是"0"的所有命令;优先化";通过设置contextualStrings。。。

var contextualString = ["hello world", "goodbye world"]
recognitionRequest.contextualStrings = contextualString

然后在recognitionTask:中过滤这些结果

recognitionTask = speechRecognizer.recognitionTask(with: recognitionRequest) { result, error in
var isFinal = false

if let result = result {                
for transcription in result.transcriptions {
print("Pondering (result.bestTranscription.formattedString)")
if contextualString.contains(transcription.formattedString.lowercased()) {
print("Found (transcription.formattedString)")
}
}
}

//...
}

示例代码可在https://developer.apple.com/documentation/speech/recognizing_speech_in_live_audio如果你想玩它并测试它的极限

相关内容

  • 没有找到相关文章

最新更新