使用微軟的SPXSpeechRecognizer語音轉(zhuǎn)文字出現(xiàn)卡頓五六秒的情況携狭。
解決辦法:
// 優(yōu)雅地停止語音識(shí)別
// 將高計(jì)算量的邏輯放在后臺(tái)線程中執(zhí)行
dispatch_queue_t calculationQueue = dispatch_queue_create("com.example.calculation", DISPATCH_QUEUE_SERIAL);
dispatch_async(calculationQueue, ^{
// 在需要的地方調(diào)用停止語音識(shí)別的方法
[self stopAndReleaseSpeechRecognizer];
});
- (void)stopAndReleaseSpeechRecognizer {
if (self.speechRecognizerS) {
@try {
[self.speechRecognizerS stopContinuousRecognition];
self.speechRecognizerS = nil;
}
@catch (NSException *exception) {
NSLog(@"Exception occurred while stopping continuous recognition: %@", exception.reason);
}
}
}