首页 > 解决方案 > 不同语言的iOS语音重置

问题描述

我有一个当前的语音识别捕获效果很好 - 你说你想要什么,它就可以了。对于它的价值来说也相当准确......

我遇到的问题是这样的:

但是,如果我停止录制并使用原始语言重置,它会正常工作。例如,即使从韩语开始,只要我停下来,切换到...韩语...然后再次按开始,它就可以了。不管我做了多少次这个过程。

问题是,继续我的例子,如果我从韩语开始切换到一种语言,甚至是英语,它会给我这个错误(包含在我的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];

}

更新:

我发现,在连续两次重置后(保持相同的新选择的语言),录音按预期工作。

但就目前而言,我找不到一个解决方案,让它在更改语言后第一次立即工作......奇怪。

标签: iosobjective-cspeech-recognitionsfspeechrecognizer

解决方案


推荐阅读