tags:

views:

935

answers:

2

My question is how can I load a grammar file that uses the tags they list in the MSDN docs? I want to use the format tags that are documented in MSDN under the heading Grammar Format Tags (SAPI 5.3).

http://msdn.microsoft.com/en-us/library/ms723634(VS.85).aspx

There it lists tags like DEFINE, LIST, OPT etc. However whenever I try to use those tags in the grammar.xml file I get an error saying that that tag is not supported.

If use a grammar file that only uses the tags one-of, item, etc. That are listed here in the MSDN; the grammar file loads.

http://msdn.microsoft.com/en-us/library/ms870140.aspx

I know it is probably something simple but I cant seem to figure it out...

Grammar file...that works

  <grammar xmlns="http://www.w3.org/2001/06/grammar"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.w3.org/2001/06/grammar
                                http://www.w3.org/TR/speech-grammar/grammar.xsd"
            xml:lang="en-US" version="1.0" root="command">


  <rule id="command" scope="public">

    <one-of>
      <item>nail</item>
      <item>hammer</item>
      <item>saw</item>
    </one-of>
  </rule>

   </grammar>

Code listing-------------------

    public Form1()
    {

        InitializeComponent();

        // set up the recognizer
        _speechRecognizer = new SpeechRecognizer();
        _speechRecognizer.Enabled = false;
        _speechRecognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_speechRecognizer_SpeechRecognized);

        // set up the command and control grammar
        Grammar commandGrammar = new Grammar(@"grammar.xml");
        commandGrammar.Name = "main command grammar";
        commandGrammar.Enabled = true;

        // activate the command grammer
        _speechRecognizer.LoadGrammar(commandGrammar);

        _speechRecognizer.Enabled = true;
    }
+1  A: 

You appear to be using c#, and therefore the .NET interface to the speech system. As far as I can tell the .NET interface only explicitly supports the W3C SRGS XML grammar format, http://www.w3.org/TR/speech-grammar/. While the grammar format you link to is an MS specific format, which they seem to call CFG. Only the lowerlevel COM API gives details of the CFG format.

You should be able to do the same things in SRGS as in CFG.

You may be able to load the binary version of CFG after compiling it using the SDK tools.

Conor OG
A: 

Can u send me your complete code because _speechRecognizer_SpeechRecognized() does't exist?

If acheived anything new so please that also @ [email protected]