c# - WP8 中的 SpeechRecognizerUI 导致高崩溃次数?

标签 c# windows-phone-8 speech-recognition speech-to-text

我一直在开发一个笔记应用程序,我已经包含了 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)
{
    //...
}

关于c# - WP8 中的 SpeechRecognizerUI 导致高崩溃次数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25541151/

相关文章:

c# - 如何检测点击当前选定的 PivotItem 的标题

android - 是否可以仅更新移动平台上应用程序的某些部分?

Swift - 如何语音基本运算符 - 符号(+,-,×)?

c# - 如何在 JsonConverter 中注入(inject)/访问 HttpContext?

c# - NServiceBus 指定处理程序执行的顺序

c# - Windows Phone 8 设备可以用于测试使用 WP SDK 7.1 构建的应用程序吗

Azure 语音转文本 cURL 调用失败

java - 使用过零率区分浊音/清音语音

c# - 使用 UIElement 将 FlowDocument 导出为 rtf

c# - 将颜色淡化为白色(增加亮度)