tags:

views:

8

answers:

1

Given the following which can be loaded into MS SAPI 5.1:

<GRAMMAR LANGID="409"> 
    <RULE NAME="top rule" TOPLEVEL="ACTIVE"> 
        <OPT>hello</OPT> 
        <P>my name is fred</P> 
    </RULE> 
</GRAMMAR>

How can I do the same programmatically, specifically with regard to the optional element.

I would guess it is done here:

state.AddWordTransition(nextState, "hello", " ", SpeechGrammarWordType.SGLexical, s, id, ref propValue, 1F);

...and it is probably the propValue. But what is the syntax (e.g, propValue="OPT=true" - does not work of course)

Thanks!

A: 

Optional words need an epsilon (empty) transition to the next state, so add:

state.AddWordTransition(nextState, NULL, NULL, SpeechGrammarWordType.SGLexical, s, id, ref propValue, 1F);

to add the epsilon transition.

Eric Brown
I was unable to find that in the MS docs.
tom
Thank you very much!
tom
It's sort of implicit in the statement 'If psz is NULL, an epsilon arc will be added.'
Eric Brown