我一直在处理笔记应用程序,我已经包含了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");
}
答案 0 :(得分:0)
在使用recoResult.RecognitionResult.Text之前,你需要检查一下。
if (recoResult.RecognitionResult != null)
{
//...
}