c# - Audio device error encountered. - Error Code: 0x4 -
i'm working on speech recognition program on c# (using visual basic 2013), , when compile , try out, works fine first command gives me weird exception when speak second command. details:
a first chance exception of type 'system.speech.internal.synthesis.audioexception' occurred in system.speech.dll
an exception of type 'system.speech.internal.synthesis.audioexception' occurred in system.speech.dll not handled in user code
additional information: audio device error encountered. - error code: 0x4
my code quite few lines long, here's first , 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 stuff" + stuff); break; //weather case "hows weather": getweather(); jarvis.speak("the temperature in " + town + " " + 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 causes problem. highly appreciated, in advance.
stack tracing shows:
expression: ((system.speech.internal.synthesis.audioexception)$exception).stacktrace value: @ system.speech.internal.synthesis.voicesynthesis.speak(prompt prompt) @ system.speech.synthesis.speechsynthesizer.speak(prompt prompt) @ system.speech.synthesis.speechsynthesizer.speak(string texttospeak) @ jarvistest.form1._recognizer_speechrecognized(object sender, speechrecognizedeventargs e) in c:\users\aristotelis\documents\visual studio 2012\projects\jarvistest\jarvistest\form1.cs:line 77 @ system.speech.recognition.speechrecognitionengine.speechrecognizedproxy(object sender, speechrecognizedeventargs e)
this type of error occurs when speech device damaged. have seen http://social.msdn.microsoft.com/forums/vstudio/en-us/9075023b-8bc4-4632-a573-77470b403a48/i-get-an-audioexception-0x2 ???
Comments
Post a Comment