我在Windows Phone 8.1应用程序中的语音识别问题很严重 .
我的代码(我在Google中发现了类似的内容):
private SpeechRecognizer speechRecognizer;
public async Task InitializeSpeechRecognizerAsync()
{
speechRecognizer = new SpeechRecognizer();
SpeechRecognitionTopicConstraint topicConstraint =
new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation,
"dictation");
speechRecognizer.Constraints.Add(topicConstraint);
await speechRecognizer.CompileConstraintsAsync();
}
并点击事件:
private async void BtnAge_Click(object sender, RoutedEventArgs e)
{
SpeechRecognitionResult recognitionResult = await speechRecognizer.RecognizeWithUIAsync();
}
当然 - 它不起作用并抛出异常
Operation is not valid due to the current state of the object.
我知道如何识别Windows Phone 8.0上的语音,但不知道如何在WP 8.1上执行此操作 .
2 回答
确保您的设备安装了合适的语音语言并与Recognizer对象关联 . 您可以使用与语言相关的属性进行验证,如documented on MSDN
尝试将代码用于调用RecognizeWithUIAsync()的相同方法初始化识别器 . 这是我自己的应用程序中的代码,它肯定有效: