SFSpeechAudioBufferRecognitionRequest *recognitionRequest = [[SFSpeechAudioBufferRecognitionRequest alloc] init];
recognitionRequest.contextualStrings = @[@"Your specific word", @"short custom phrases that are unique to your app"];
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
}
})
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)")
}
}
}
//...
}
3条答案
按热度按时间lnvxswe21#
您可以尝试使用SFSpeechAudioBufferRecognitionRequest的contextualStrings属性设置高优先级或设置词汇表中没有的某些单词。有关详细信息,请查看此处:https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/1649391-contextualstrings?language=objc
xzv2uavs2#
我认为你不能限制
SFSpeechRecognizer
的词汇量,但只有当你想要的单词被识别时,你才能发射action。当你得到你的输出,你可以尝试这样做:
cld4siwp3#
经过反复试验,最好的解决方案是将桑塔塔姆和加拉西诺的答案结合起来。
您可以首先通过设置
contextualStrings
...来指定所有应该“优先化”的命令。...然后在
recognitionTask
中过滤这些结果:如果您想尝试使用它并测试其限制,可以在https://developer.apple.com/documentation/speech/recognizing_speech_in_live_audio中找到示例代码