日期:2014-05-17 浏览次数:21223 次
static bool completed;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
using (SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine())//new CultureInfo("zh-CN")
{
//Create and load the exit grammar.
Grammar exitGrammar = new Grammar(new GrammarBuilder("exit"));
exitGrammar.Name = "Exit Grammar";
recognizer.LoadGrammar(exitGrammar);
// Attach event handlers to the recognizer.
recognizer.SpeechRecognized +=new EventHandler<SpeechRecognizedEventArgs>(SpeechRecognizedHandler);
// Assign input to the recognizer.
recognizer.SetInputToDefaultAudioDevice();
// Begin asynchronous recognition.
RtxtBox.Text = "马上开始...\r";
completed = false;
recognizer.RecognizeAsync(RecognizeMode.Multiple);
// Wait for recognition to finish.
while (!completed)
{
Thread.Sleep(333);