ios - 不同语言的iOS语音重置
问题描述
我有一个当前的语音识别捕获效果很好 - 你说你想要什么,它就可以了。对于它的价值来说也相当准确......
我遇到的问题是这样的:
如果我在停止和启动后尝试更改语言,则会失败并出现以下错误
2018-05-23 00:51:51.878921-0400 APP[1237:332833] Speech error: The operation couldn’t be completed. (kAFAssistantErrorDomain error 209.) 2018-05-23 00:51:51.922965-0400 APP[1237:332833] Speech error: Corrupt
但是,如果我停止录制并使用原始语言重置,它会正常工作。例如,即使从韩语开始,只要我停下来,切换到...韩语...然后再次按开始,它就可以了。不管我做了多少次这个过程。
问题是,继续我的例子,如果我从韩语开始切换到另一种语言,甚至是英语,它会给我这个错误(包含在我的FYI 中)。recognitionTaskWithRequest
似乎起始语言与它是否有效无关,只要我选择不同的语言它就会失败,而当我选择相同的起始语言时它就会起作用。
// Note: self.inputLanguageIdentifier is changed when you select a new language.
// I have tested to ensure this ID is correct each time.
// I.E. Korean prints ko-KR, English of course en-US, etc.
NSLocale *locale = [NSLocale alloc] initWithLocaleIdentifier:self.inputLanguageIdentifier]
speechRecognizer = [[SFSpeechRecognizer alloc] initWithLocale:locale];
speechRecognizer.delegate = self;
recognitionRequest = [[SFSpeechAudioBufferRecognitionRequest alloc] init];
AVAudioInputNode *inputNode = audioEngine.inputNode;
recognitionRequest.shouldReportPartialResults = YES;
recognitionTask = [speechRecognizer recognitionTaskWithRequest:recognitionRequest resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {
BOOL isFinal = NO;
if (result && !userDidTapCancel) {
// in the console.
NSLog(@"RESULT:%@", result.bestTranscription.formattedString);
[self updateTextForResult:result.bestTranscription.formattedString];
isFinal = !result.isFinal;
}
if (error) {
NSLog(@"Speech error: %@", error.localizedDescription);
[self stopListening];
}
}];
我stopListening
的是这样的:
- (void)stopListening {
isListening = NO;
[audioEngine stop];
[recognitionRequest endAudio];
[recognitionTask cancel];
}
更新:
我发现,在连续两次重置后(保持相同的新选择的语言),录音按预期工作。
但就目前而言,我找不到一个解决方案,让它在更改语言后第一次立即工作......奇怪。
解决方案
推荐阅读
- windows - 在 Windows 服务中打开的对话框窗口
- javascript - 为什么我们不能在一个库中拥有一个包含 React 和 React-DOM 库的库?
- c - 从 .raw 图像文件格式读取二进制数据
- android - 如何在 Android 设备上运行带有 Node js 后端的 React Native 应用程序?
- r - FriedmanTestBMR 使用一个多任务分类器 - mlr
- doctrine-orm - 覆盖供应商库中的 Doctrine 实体类以删除实体属性
- asp.net-core - ASP .Net Core 3.1 使用自定义名称构建到客户文件夹而不是 netcoreapp3.1
- xml - XPATH:在一场比赛中得分最多的球员是谁?
- flutter - 从 Flutter 中的子小部件按后退按钮后如何不调用 didChangeDependencies()?
- node.js - Connection:keep-alive 没有为 NodeJS 中的 HTTP 请求保持套接字连接