设置进程内识别引擎的SAPI代码如下所示:
ISpeechRecoContext cpRecoCtx;
// create the recognition context
cpRecoCtx = new SpeechLib.SpInProcRecoContext();
((SpInProcRecoContext)cpRecoCtx).Recognition +=
new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);
/****** END: set up recognition context *****/
那么我如何设置我的音频输入默认音频输入在c#?我已经在c++中找到了解决方案,但需要一个c#。
默认音频输入对象为SpMMAudioIn
。
ISpeechRecoContext cpRecoCtx;
SpMMAudioIn audio = new SpMMAudioIn;
// set the audio input
cpRecoCtx.GetRecognizer.SetInput(audio);
Eric,你的代码不工作。首先,没有"GetRecognizer"方法。我已经把这条线换成了正确的。你指的是哪个版本的SAPI ?我使用的是"微软语音对象库5.4"。接下来,您不会像前面提到的那样展示如何设置设备的音频输入。下面的代码应该可以工作,但它不允许您设置设备ID,这在VB6中一直有效。尝试将。deviceid设置为任何值会抛出异常:
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;
当然,必须有一种方法将输入发送到有效的MMSYS (WaveInOpen)输入流。