简体   繁体   English

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

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

I'm working on a speech recognition program on C# (using Visual Basic 2013), and when I compile and try it out, it works fine for the first command but gives me a weird exception when I speak the second command. 我正在使用C#(使用Visual Basic 2013)开发语音识别程序,当我进行编译和尝试时,它对于第一个命令运行正常,但是当我说第二个命令时却出现了一个奇怪的异常。 Details: 细节:

A first chance exception of type 'System.Speech.Internal.Synthesis.AudioException' occurred in System.Speech.dll System.Speech.dll中发生类型为“ System.Speech.Internal.Synthesis.AudioException”的第一次机会异常

An exception of type 'System.Speech.Internal.Synthesis.AudioException' occurred in System.Speech.dll but was not handled in user code System.Speech.dll中发生类型'System.Speech.Internal.Synthesis.AudioException'的异常,但未在用户代码中处理

Additional information: Audio device error encountered. 附加信息:遇到音频设备错误。 - Error Code: 0x4 -错误代码:0x4

My code is quite a few lines long, but here's the first and possibly related part: 我的代码长了几行,但这是第一部分,可能是相关的部分:

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;

I'm not sure what causes the problem. 我不确定是什么原因引起的。 Any help is highly appreciated, thanks in advance. 感谢您的任何帮助,在此先感谢。

Stack tracing shows: 堆栈跟踪显示:

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)

This type of error generally occurs when your speech device is damaged. 当您的语音设备损坏时,通常会发生此类错误。 Have you seen http://social.msdn.microsoft.com/Forums/vstudio/en-US/9075023b-8bc4-4632-a573-77470b403a48/i-get-an-audioexception-0x2 ??? 您是否看到过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.

相关问题 消息:遇到致命错误。 在“C:\Program Files\dotnet”中找不到执行应用程序所需的库“hostpolicy.dll” - Message: A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Program Files\dotnet' 打开队列管理器名称时遇到错误 =.... 原因代码 = 2354 - Error encountered on opening Queue Manager name = .... Reason code = 2354 代码中的错误X - Error X in code SignedXml 报告“遇到未知转换。” - SignedXml reports “Unknown transform has been encountered.” 设备上的WNS错误0x880403E8 - WNS error 0x880403E8 on device C#:遇到异常。 这可能是由扩展引起的 - C#: An exception has been encountered. This may be caused by an extension 未处理AudioException /语音识别程序中的音频设备错误 - AudioException was unhandled / Audio device error in speech recognition program 错误:尝试读取结果集时遇到致命错误 - Error : Fatal error encountered attempting to read the resultset 错误:命令执行期间遇到致命错误 - Error: Fatal error encountered during command execution 机器人遇到错误或错误。 要继续运行此机器人,请修复机器人源代码 - The bot encountered an error or bug. To continue to run this bot, please fix the bot source code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM