我正在处理以下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Windows.Forms;
namespace US_Speech_Recognizer
{
public class RecognizeSpeech
{
private SpeechRecognitionEngine sEngine; //Speech recognition engine
private SpeechSynthesizer sSpeak; //Speech synthesizer
public RecognizeSpeech()
{
//Make the recognizer ready
sEngine = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
//Load grammar
Choices sentences = new Choices();
sentences.Add(new string[] { "I am hungry" });
GrammarBuilder gBuilder = new GrammarBuilder(sentences);
Grammar g = new Grammar(gBuilder);
sEngine.LoadGrammar(g);
//Add a handler
sEngine.SpeechRecognized +=new EventHandler<SpeechRecognizedEventArgs>(sEngine_SpeechRecognized);
//Ask the to speak
sSpeak = new SpeechSynthesizer();
sSpeak.Rate = -2;
sSpeak.Speak("Please speak the sentence above");
//Configure the recognizer to Mike
sEngine.SetInputToDefaultAudioDevice();
sEngine.RecognizeAsync(RecognizeMode.Multiple);
}
//Start the speech recognition task
private void sEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
MessageBox.Show(e.Result.Confidence.ToString());
}
}
}
在这里,我正在加载来自 Mike 的输入。但是,我需要从计算机内部输入的内容中加载输入,而不是那样做sSpeak.Speak("Please speak the sentence above");
。如何将此计算机语音加载为语音识别器的输入?