SAPI and Windows 7 Problem
Asked Answered
A

1

2

I'm trying to recognize speech with Windows 7 but it always recognizes a speech as a command or just says "What was that?".

How I can get all speeches?

CODE:

SpeechRecognizer _speechRecognizer;

    public Window1()
    {
        InitializeComponent();

        // set up the recognizer
        _speechRecognizer = new SpeechRecognizer();
        _speechRecognizer.Enabled = false;
        _speechRecognizer.SpeechRecognized +=
      new EventHandler<SpeechRecognizedEventArgs>(_speechRecognizer_SpeechRecognized); }
Anthropoid answered 18/11, 2010 at 8:53 Comment(0)
O
5

Perhaps you want to use the .net System.Speech namespace instead of SAPI? There is a very good article that was published a few years ago at http://msdn.microsoft.com/en-us/magazine/cc163663.aspx. It is probably the best introductory article I’ve found so far. It is a little out of date, but very helfpul. (The AppendResultKeyValue method was dropped after the beta.)

Are you trying to use a shared recognizer? That may be why you are seeing commands. Do you have a specific task for recognition? In that case, you would be better served with a task specific grammar and an inproc recognizer.

If you need to handle any words, use the DictationGrammar that comes with System.Speech. See http://msdn.microsoft.com/en-us/library/system.speech.recognition.dictationgrammar%28VS.85%29.aspx

For fun, I whipped together the simplest .NET windows forms app to use a dictation grammar that I could think of. I created a form. Dropped a button on it and made the button big. Added a reference to System.Speech and the line:

using System.Speech.Recognition;

Then I added the following event handler to button1:

private void button1_Click(object sender, EventArgs e)
{         
    SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();
    Grammar dictationGrammar = new DictationGrammar();
    recognizer.LoadGrammar(dictationGrammar);
    try
    {
        button1.Text = "Speak Now";
        recognizer.SetInputToDefaultAudioDevice();
        RecognitionResult result = recognizer.Recognize();
        button1.Text = result.Text;
    }
    catch (InvalidOperationException exception)
    {
        button1.Text = String.Format("Could not recognize input from default aduio device. Is a microphone or sound card available?\r\n{0} - {1}.", exception.Source, exception.Message);
    }
    finally
    {
        recognizer.UnloadAllGrammars();
    }                          
}
Ovenware answered 18/11, 2010 at 17:17 Comment(5)
Thanks Michael. I need to recognize every word. All examples in the link you gave are about building commands actually. How can I get all?Anthropoid
If you use the desktop recognizer (That ships in Windows Vista and 7), it comes with a built in Dictation Grammar. See msdn.microsoft.com/en-us/library/…Ovenware
I updated the answer to include an example of using the DictationGrammar.Ovenware
@Michael Levy: i used your code but it is not giving me the accurate answer to what i speak.. :/ why so?Baedeker
Recognizer results can vary based on many factors. Background noise, Microphone quality, audio input settings and levels. In Windows 7 with the Dictation grammar, you can also use Windows 7 Speech Recognition features to train the recognizer to better recognize a single speaker. See windows.microsoft.com/en-US/windows7/Set-up-Speech-Recognition for more info.Ovenware

© 2022 - 2024 — McMap. All rights reserved.