繁体   English   中英

遇到音频设备错误。 -错误代码:0x4

[英]Audio device error encountered. - Error Code: 0x4

我正在使用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)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM