Windows Phone 8.1应用程序中的语音识别器在线

时间:2015-11-21 14:35:00

标签: c# windows-phone-8.1 speech-recognition speech-to-text

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 个答案:

答案 0 :(得分:0)

确保您的设备安装了合适的语音语言并与Recognizer对象关联。您可以使用与语言相关的属性进行验证documented on MSDN

答案 1 :(得分:0)

尝试将代码初始化识别器,方法与调用RecognizeWithUIAsync()的方法相同。 这是我自己的应用程序中的代码,它确实有效:

public async Task<string> RecognizeSpeech()
{
  SpeechRecognizer recognizer = new SpeechRecognizer();
  SpeechRecognitionTopicConstraint topicConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "Message");
  recognizer.Constraints.Add(topicConstraint);
  await recognizer.CompileConstraintsAsync();
  SpeechRecognitionResult result = await recognizer.RecognizeWithUIAsync();
  if (result.Confidence == SpeechRecognitionConfidence.High || result.Confidence == SpeechRecognitionConfidence.Medium)
  {
    return result.Text;
  }
  return null;
}