开发者

Programmatically turn off the automation features of windows speech recognition?

开发者 https://www.devze.com 2022-12-20 04:24 出处:网络
I\'m making a program that uses the system.speech namespace (it\'s a simple program that will launch movies). I load all of the filenames from a folder and add them to the grammars I want to use. It\'

I'm making a program that uses the system.speech namespace (it's a simple program that will launch movies). I load all of the filenames from a folder and add them to the grammars I want to use. It's working remarkably well, however there is a hitch: I DON'T want the windows speech recognition to interact with windows at all (ie. when I say start, I don't want the start menu to open... I don't want anything to happen).

Likewise, I have a listbox for the moment that lists all of the movies found in the directory. When I say the show/movie that I want to open, the program isn't recognizing that the name was said because windows speech recognition is selecting the listboxitem from the list instead of passing that to 开发者_JAVA百科my program.

The recognition is working otherwise, because I have words like "stop", "play", "rewind" in the grammar, and when I catch listener_SpeechRecognized, it will correctly know the word(s)/phrase that I'm saying (and currently just type it in a textbox).

Any idea how I might be able to do this?


I'd use the SpeechRecognitionEngine class rather than the SpeechRecognizer class. This creates a speech recognizer that is completely disconnected from Windows Speech Recognition.


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号