C# 自动识别所有英语单词

C# 自动识别所有英语单词,c#,winforms,speech-recognition,C#,Winforms,Speech Recognition,我有一个windows窗体应用程序。我想做一个语音识别。问题是,我使用的语法仅限于我的选项列表(请参阅下面的程序)。我希望我的程序能够识别所有单词 Choices sList = new Choices(); sList.Add(new string[] { "hello", "test", "it works", "how", "are", "you", "today", "i", "am", "fine", "exit", "close", "quit", "so" }); Gram

我有一个windows窗体应用程序。我想做一个
语音识别
。问题是,我使用的
语法仅限于我的选项列表(请参阅下面的程序)。我希望我的程序能够识别所有单词

Choices sList = new Choices();
sList.Add(new string[] { "hello", "test", "it works", "how", "are", "you", "today", "i", "am", "fine", "exit", "close", "quit", "so" });
    Grammar gr = new Grammar(new GrammarBuilder(sList));
你知道如何让我的程序识别所有单词吗

源代码: 声明:

using System.Speech;
using System.Speech.Recognition;
using System.Speech.Synthesis;
private void button2_Click(object sender, EventArgs e)
{
    button2.Enabled = false; // Start record
    button3.Enabled = true;  // Stop record
    Choices sList = new Choices();
    sList.Add(new string[] { "hello", "test", "it works", "how", "are", "you", "today", "i", "am", "fine", "exit", "close", "quit", "so" });
    Grammar gr = new Grammar(new GrammarBuilder(sList));
    try
    {
        sRecognize.RequestRecognizerUpdate();
        sRecognize.LoadGrammar(gr);
        sRecognize.SpeechRecognized += sRecognize_SpeechRecognized ;
        sRecognize.SetInputToDefaultAudioDevice();
        sRecognize.RecognizeAsync(RecognizeMode.Multiple);
        sRecognize.Recognize();
    }
    catch
    {
        return;
    }
 }

private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
    if (e.Result.Text == "exit")
    {
        Application.Exit();
    }
    else
    {
        textBox1.Text = textBox1.Text + " " + e.Result.Text.ToString(); 
    }

}
节目:

using System.Speech;
using System.Speech.Recognition;
using System.Speech.Synthesis;
private void button2_Click(object sender, EventArgs e)
{
    button2.Enabled = false; // Start record
    button3.Enabled = true;  // Stop record
    Choices sList = new Choices();
    sList.Add(new string[] { "hello", "test", "it works", "how", "are", "you", "today", "i", "am", "fine", "exit", "close", "quit", "so" });
    Grammar gr = new Grammar(new GrammarBuilder(sList));
    try
    {
        sRecognize.RequestRecognizerUpdate();
        sRecognize.LoadGrammar(gr);
        sRecognize.SpeechRecognized += sRecognize_SpeechRecognized ;
        sRecognize.SetInputToDefaultAudioDevice();
        sRecognize.RecognizeAsync(RecognizeMode.Multiple);
        sRecognize.Recognize();
    }
    catch
    {
        return;
    }
 }

private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
    if (e.Result.Text == "exit")
    {
        Application.Exit();
    }
    else
    {
        textBox1.Text = textBox1.Text + " " + e.Result.Text.ToString(); 
    }

}
这个程序的问题是无法识别所有单词,对于我的项目,我想让它识别所有单词

Choices sList = new Choices();
sList.Add(new string[] { "hello", "test", "it works", "how", "are", "you", "today", "i", "am", "fine", "exit", "close", "quit", "so" });
    Grammar gr = new Grammar(new GrammarBuilder(sList));

谢谢Stackoverflowers

如果我理解正确,您的意思是,这正是您需要的: 只需在听写模式下使用SpeechRecognitionEngine,即可识别单词(参见示例)