WP8中的SpeechRecognizerUI导致高崩溃次数
本文关键字:崩溃 高崩溃 中的 SpeechRecognizerUI WP8 | 更新日期: 2023-09-27 18:19:48
我一直在开发一个笔记应用程序,我已经包含了SpeechRecognizerUI,这样用户就可以直接从语音中记笔记。把这个应用程序放到商店后,我注意到崩溃次数非常高。我也收到了一些用户的投诉,说这个应用程序随机崩溃。我试了很多次,但没有崩溃。所以我从开发中心网站导出了堆栈跟踪。
所有的崩溃都与SpeechRecognizerUI有关。。有人知道怎么解决这个问题吗?
这是我在页面中使用的代码:-
SpeechRecognizerUI recoWithUI; //Speech to text
SpeechSynthesizer synth; //Text to speech
public NoteView()
{
InitializeComponent();
recoWithUI = new SpeechRecognizerUI();
synth = new SpeechSynthesizer();
recoWithUI.Recognizer.AudioProblemOccurred += Recognizer_AudioProblemOccurred;
}
private async void RecordButton_Click(object sender, EventArgs e)
{
try
{
SpeechRecognitionUIResult recoResult = await recoWithUI.RecognizeWithUIAsync();
if (NoteBox.Text == "")
NoteBox.Text = recoResult.RecognitionResult.Text;
else
NoteBox.Text = NoteBox.Text + " " + recoResult.RecognitionResult.Text;
}
catch (Exception ex)
{
}
}
async void Recognizer_AudioProblemOccurred(SpeechRecognizer sender, SpeechAudioProblemOccurredEventArgs args)
{
if (args.Problem == SpeechRecognitionAudioProblem.NoSignal)
await synth.SpeakTextAsync("I can't hear you");
else if (args.Problem == SpeechRecognitionAudioProblem.TooFast)
await synth.SpeakTextAsync("That's too fast");
else if (args.Problem == SpeechRecognitionAudioProblem.TooLoud)
await synth.SpeakTextAsync("That's too loud.");
else if (args.Problem == SpeechRecognitionAudioProblem.TooNoisy)
await synth.SpeakTextAsync("There's too much noise");
else if (args.Problem == SpeechRecognitionAudioProblem.TooQuiet)
await synth.SpeakTextAsync("Try speaking louder");
else if (args.Problem == SpeechRecognitionAudioProblem.TooSlow)
await synth.SpeakTextAsync("Try speaking faster");
}
在使用recoResult.RecognitionResult.Text.之前,您需要对此进行检查
if (recoResult.RecognitionResult != null)
{
//...
}