Browse
 
Tools
Rss Categories

LVSpeechPort::ActivateGrammar

Reference Number: AA-00744 Views: 8042 0 Rating/ Voters

If you wish to use a speech port's loaded SRGS grammar for decode, you need to activate it. Activating a grammar puts it in the multi-grammar grammarset called LV_ACTIVE_GRAMMAR_SET. The grammars that were activated can then be used for a decode by specifying LV_ACTIVE_GRAMMAR_SET as the grammarset parameter in a call to Decode, or by setting the STREAM_PARM_GRAMMAR_SET equal to the LV_ACTIVE_GRAMMAR_SET before calling StreamStart.The reason for this mechanism is to maintain backward compatibility with previous APIs.

When ActivateGrammar is called, first the grammar is searched for among the grammars in the speech port's loaded grammars. If it can not be found there, the collection of application level grammars is searched.

Function

  • int ActivateGrammar(const char* gram_name)

Parameters

gram_name

The identifier for the grammar being activated. This is the same identifier that was given to the grammar when it was loaded.

Return Values

LV_SUCCESS

No errors; this grammar is now active.

LV_FAILURE, LV_INVALID_GRAMMAR_LABEL

This grammar could not be activated, because it was not found in the speech port's set of loaded grammars.

LV_EXCEPTION

An exception occurred while processing the request.

Remarks

Detailed error and warning messages are sent to the speech port's logging callback function at priorities 0 and 1, respectively.

Example

C++ Code

  1. // Below is an example of a subroutine that loads and activates a grammar.

  2. void LoadGrammar(char *grammar_name, char *grammar_file)
  3. {
  4. printf("Loading the grammar and activating it.\n");
  5. error code = port.LoadGrammar(grammar_name, grammar_file);

  6. // Once you load up a grammar you can activate and deactivate it
  7. // at any point during the call flow.
  8. error code = port.ActivateGrammar(grammar_name);
  9. error code = port.StreamSetParameter(STREAM_PARM_GRAMMAR_SET,
    LV_ACTIVE_GRAMMAR_SET);
  10. }

See Also