我正在使用此代码(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);
//}
}
});
除了法语不被识别外,它的效果非常好,我把手机用法语但不起作用。是否存在设置某个地方的论点?
答案 0 :(得分:0)
经过一番搜索,我发现" locale"可以在初始化SpeechRecognizer
对象时定义,如:
private SFSpeechRecognizer SpeechRecognizer = new SFSpeechRecognizer (new NSLocale ("fr_FR"));
有效!