我想将语音识别与我的应用程序集成。
我能用SpeechRecognizerUI做到这一点但是当我用SpeechRecognizer创建自己的UI时会产生异常吗?为什么这样.. 此代码始终生成异常并显示“Exception Raised”。
我不想使用SpeechRecognizerUI。
private async void Button_Click(object sender, RoutedEventArgs e)
{
SpeechRecognizer speechrecognizer = new SpeechRecognizer();
try
{
SpeechRecognitionResult result = await speechrecognizer.RecognizeAsync();
if (result.TextConfidence != SpeechRecognitionConfidence.Rejected)
{
txt.Text = result.Text;
}
}
catch (Exception err)
{
int privacyPolicyHResult = unchecked((int)0x80045509);
if (err.HResult == privacyPolicyHResult)
{
MessageBox.Show("You will need to accept the speech privacy policy in order to use speech recognition in this app.");
}
else
{
MessageBox.Show("Exception Raised");
}
}