1

我正在使用 C# 上的语音识别程序(使用 Visual Basic 2013),当我编译并尝试它时,它对第一个命令工作正常,但当我说出第二个命令时给了我一个奇怪的异常。细节:

System.Speech.dll 中出现“System.Speech.Internal.Synthesis.AudioException”类型的第一次机会异常

System.Speech.dll 中出现“System.Speech.Internal.Synthesis.AudioException”类型的异常,但未在用户代码中处理

附加信息:遇到音频设备错误。- 错误代码:0x4

我的代码有好几行,但这是第一个可能相关的部分:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.IO;
using System.Xml;
using System.Web;

namespace JarvisTest
{
public partial class Form1 : Form
{
    SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
    SpeechSynthesizer JARVIS = new SpeechSynthesizer();
    string QEvent;
    string ProcWindow;
    double timer = 10;
    int count = 1;
    Random rnd = new Random();

    string Temperature;
    string Condition;
    string Humidity;
    string WindSpeed;
    string Town;
    string TFCond;
    string TFHigh;
    string TFLow;
    string Stuff;


    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        _recognizer.SetInputToDefaultAudioDevice();
        _recognizer.LoadGrammar(new DictationGrammar());
        _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Users\Aristotelis\Documents\JarvisTest.txt")))));
        _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);
        _recognizer.RecognizeAsync(RecognizeMode.Multiple);
    }


    void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        int ranNum = rnd.Next(1, 10);

        string speech = e.Result.Text;
        switch (speech)
        {
            //WOLFRAM
            case "ram":               
                WolframAlpha();
                JARVIS.Speak("time for stuff" + Stuff);
                break;

            //WEATHER

            case "hows the weather":
                GetWeather();
                JARVIS.Speak("The temperature in " + Town + " is " + Temperature + " degrees.");
                break;

            //GREETINGS
            case "hello":
            case "hello jarvis":
                if (ranNum < 6) { JARVIS.Speak("Hello sir"); }
                else if (ranNum > 5) { JARVIS.Speak("Hi"); }
                break;

我不确定是什么导致了问题。任何帮助都非常感谢,在此先感谢。

堆栈跟踪显示:

Expression: ((System.Speech.Internal.Synthesis.AudioException)$exception).StackTrace
Value:
at System.Speech.Internal.Synthesis.VoiceSynthesis.Speak(Prompt prompt)
at System.Speech.Synthesis.SpeechSynthesizer.Speak(Prompt prompt)
at System.Speech.Synthesis.SpeechSynthesizer.Speak(String textToSpeak)
at JarvisTest.Form1._recognizer_SpeechRecognized(Object sender, SpeechRecognizedEventArgs e) in c:\Users\Aristotelis\Documents\Visual Studio 2012\Projects\JarvisTest\JarvisTest\Form1.cs:line 77
at System.Speech.Recognition.SpeechRecognitionEngine.SpeechRecognizedProxy(Object sender, SpeechRecognizedEventArgs e)
4

1 回答 1

0

当您的语音设备损坏时,通常会发生此类错误。你见过http://social.msdn.microsoft.com/Forums/vstudio/en-US/9075023b-8bc4-4632-a573-77470b403a48/i-get-an-audioexception-0x2 ???

于 2013-08-13T07:03:08.483 回答