c# - How to execute a particular part of code asynchronously in a class -
i creating speech recognition engine that's going respond user commands.i have created button enable , disable speech recognition per user convenience.i have used dispose() of speech engine disable speech recoginition.here code
private void button1_click(object sender, routedeventargs e) { engineon = !engineon; if (engineon) { speechengine = speech.createspeechengine(); //speech class creates , returns new speech engine. speechengine.audiolevelupdated += new eventhandler<audiolevelupdatedeventargs>(speechengine_audiolevelupdated); // use system's default microphone speechengine.setinputtodefaultaudiodevice(); speechengine.loadgrammar(new dictationgrammar()); // start listening speechengine.recognizeasync(recognizemode.multiple); } else { speechclass.myengine.dispose(); } }
but disposal of speech object takes time.how asynchronously? is there other way turn speech recognition on , off? in advance.
you use recogniseasync / recogniseasyncstop turn off , on again:
http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine.aspx
alternatively, try loading empty grammar list kinect has nothing listen out for.
additionally, i'd avoid disposing object altogether unless no longer want use (e.g. when application shutting down). there major overheads associated disposing of object (particularly speechrecognitionengine), recreating again.
Comments
Post a Comment