2

我正在制作一个使用 system.speech 命名空间的程序(这是一个将启动电影的简单程序)。我从一个文件夹中加载所有文件名并将它们添加到我想要使用的语法中。它运行得非常好,但是有一个问题:我根本不希望 Windows 语音识别与 Windows 交互(即,当我说开始时,我不希望开始菜单打开......我不'不想发生任何事情)。

同样,我现在有一个列表框,列出了在目录中找到的所有电影。当我说我想打开的节目/电影时,程序没有识别出这个名字,因为 Windows 语音识别正在从列表中选择列表框项,而不是将其传递给我的程序。

否则识别工作正常,因为我在语法中有“停止”、“播放”、“倒带”之类的词,当我捕捉到 listener_SpeechRecognized 时,它会正确地知道我说的词/短语(和目前只需在文本框中输入)。

知道我怎么能做到这一点吗?

4

2 回答 2

1

我会使用SpeechRecognitionEngine类而不是 SpeechRecognizer 类。这将创建一个与 Windows 语音识别完全断开的语音识别器。

于 2010-02-18T20:56:55.010 回答
0
private bool Status = false;

SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
Choices dic = new Choices(new String[] {
            "word1",
            "word2",
            });



public Form1()
{
    InitializeComponent();

    Grammar gmr = new Grammar(new GrammarBuilder(dic));
    gmr.Name = "myGMR";
    // My Dic

    sre.LoadGrammar(gmr);
  sre.SpeechRecognized += 
  new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
    sre.SetInputToDefaultAudioDevice();
    sre.RecognizeAsync(RecognizeMode.Multiple);
} 

private void button1_Click(object sender, EventArgs e)
{
    if (Status)
    {
        button1.Text = "START";
        Status = false;
        stslable.Text = "Stopped";
    }
    else {

        button1.Text = "STOP";
        Status = true;
        stslable.Text = "Started";
    }
}

public void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs ev)
{
   String theText = ev.Result.Text;
  MessageBox.Show(theText);
}
于 2015-09-16T18:18:43.100 回答