phoenix11
phoenix11

Reputation: 45

Creating a In proc speech recognition using sapi c#?

My SAPI code for setting up the in proc recognition engine looks like this:

ISpeechRecoContext cpRecoCtx;
// create the recognition context
cpRecoCtx = new SpeechLib.SpInProcRecoContext();

((SpInProcRecoContext)cpRecoCtx).Recognition +=
    new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);
/****** END: set up recognition context *****/

So how do I setup my audio input to default audio input in c#? I have found solutions in C++ but need one for C#.

Upvotes: 1

Views: 374

Answers (2)

FDecker
FDecker

Reputation: 41

Eric, Your code does not work. First, there is no "GetRecognizer" Method. I've replaced that line with what should work. What version of SAPI are you referring to? I am using "Microsoft Speech Object libary 5.4". Next, you don't show how to set the audio input to a device as you mentioned. The following code should work, but it does not allow you to set the device ID, which had always worked in VB6. Trying to set the .DeviceID to anything throws an exception:

SpeechLib.ISpeechRecoContext cpRecoCtx;
cpRecoCtx = new SpeechLib.SpInProcRecoContext();
SpeechLib.SpMMAudioIn audio = new SpeechLib.SpMMAudioIn();
// set the audio input
// cpRecoCtx.GetRecognizer.SetInput(audio); <--- no such method
audio.DeviceId = 1;
cpRecoCtx.Recognizer.AudioInputStream = audio;

Surely, there has GOT to be a way to sent the input to a valid MMSYS (WaveInOpen) input stream.

Upvotes: 0

Eric Brown
Eric Brown

Reputation: 13942

The default audio input object is SpMMAudioIn.

ISpeechRecoContext cpRecoCtx;
SpMMAudioIn audio = new SpMMAudioIn;
// set the audio input
cpRecoCtx.GetRecognizer.SetInput(audio);

Upvotes: 1

Related Questions