我目前有一个应用程序可以根据https://www.youtube.com/watch?v=AB9lfHDOe5U
上的教程检测我的语音在此表单的load事件中,我有以下内容
//Global Variable
SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine();
private void frmMain_Load(object sender, EventArgs e)
{
//hide border to prevent screen burnout
this.FormBorderStyle = FormBorderStyle.None;
Choices commands = new Choices();
commands.Add(new string[] { "stock", "news", "percent", "down" }); //need to read company list from db
GrammarBuilder gBuilder = new GrammarBuilder();
gBuilder.Append(commands);
Grammar grammar = new Grammar(gBuilder);
recEngine.LoadGrammarAsync(grammar);
//THIS IS PROBABLY WHERE I NEED HELP-----------
recEngine.SetInputToDefaultAudioDevice();
recEngine.SpeechRecognized += recEngine_SpeechRecognized;
}
//Event called when a word is recognized
private void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
switch (e.Result.Text)
{
case "stock":
MessageBox.Show(e.Result.Text);
break;
case "news":
MessageBox.Show(e.Result.Text);
break;
case "percent":
MessageBox.Show(e.Result.Text);
break;
case "down":
MessageBox.Show(e.Result.Text);
break;
}
}
//Used to enable the recognition to start
private void btnEnableAudio_Click(object sender, EventArgs e)
{
recEngine.RecognizeAsync(RecognizeMode.Multiple);
}
我想从扬声器而不是麦克风中读取音频,所以如果我正在播放视频,我希望能够检测到这些词。
有没有人有任何想法如何将输入设备设置到输出设备?