使用微软的SPXSpeechRecognizer语音转文字出现卡顿五六秒的情况。
解决办法:
// 优雅地停止语音识别
// 将高计算量的逻辑放在后台线程中执行
dispatch_queue_t calculationQueue = dispatch_queue_create("com.example.calculation", DISPATCH_QUEUE_SERIAL);
dispatch_async(calculationQueue, ^{
// 在需要的地方调用停止语音识别的方法
[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);
}
}
}