如何改变IOS说话识别语言?

时间:2017-12-10 10:12:26

标签: c# xamarin.ios speech-recognition

我正在使用此代码(xamarin)在我的ios应用程序中实现语音识别:

// Setup audio session
        var node = AudioEngine.InputNode;
        var recordingFormat = node.GetBusOutputFormat (0);
        node.InstallTapOnBus (0, 1024, recordingFormat, (AVAudioPcmBuffer buffer, AVAudioTime when) => {
            // Append buffer to recognition request
            LiveSpeechRequest.Append (buffer);
        });

        // Start recording
        AudioEngine.Prepare ();
        NSError error;
        AudioEngine.StartAndReturnError (out error);

        // Did recording start?
        if (error != null) {
            // Handle error and return
            return;
        }

        // Start recognition
        RecognitionTask = SpeechRecognizer.GetRecognitionTask (LiveSpeechRequest, (SFSpeechRecognitionResult result, NSError err) => {
            // Was there an error?
            if (err != null) {
                // Handle error
            } else {
                // Is this the final translation?
                //if (result.Final) {
                    Console.WriteLine ("You said \"{0}\".", result.BestTranscription.FormattedString);
                //}
            }
        });

除了法语不被识别外,它的效果非常好,我把手机用法语但不起作用。是否存在设置某个地方的论点?

1 个答案:

答案 0 :(得分:0)

经过一番搜索,我发现" locale"可以在初始化SpeechRecognizer对象时定义,如:

private SFSpeechRecognizer SpeechRecognizer = new SFSpeechRecognizer (new NSLocale ("fr_FR"));

有效!