Browse
 
Tools
Rss Categories

LV_SRE_LoadGrammar

Reference Number: AA-00712 Views: 2116 0 Rating/ Voters

Loads an SRGS grammar into a speech port for later use in a decode, DTMF decode or interpret text operation. Loading a grammar is used to define a context for the decode, a filter for the words that will be spoken. The engine will look for the words described in the grammar you are loading here.

Function

  • int LV_SRE_LoadGrammar(HPORT hport, const char* gram_name, const char* gram_uri)

Parameters

hport

The handle for the speech port you are loading the grammar into.

gram_name

The identifier for the grammar being loaded.Whenever you activate, deactivate, or unload, this is the identifier youwill use.

gram_uri

A URI that points to a valid SRGS grammar file, such as"c:/grammars/pizza.grxml", "http://www.gramsRus.com/phonenumber.gram", or "builtin:dtmf/boolean?y=1;n=2"

This URL can be a builtin reference, a file system reference, or remote HTTP reference, and as of LumenVox version 11.2.100, users may also specify resources located on secure HTTPS servers

Return Values

LV_SUCCESS

No errors; this grammar is now ready to use.

LV_GRAMMAR_SYNTAX_WARNING

The grammar file was not fully conforming, but it was understandable and is now ready for use.

LV_INVALID_HPORT

The input hport is not a valid one.

LV_FAILURE

The operation may have failed because the port was shutting down or the vocab size of the grammar is zero.The error also occurs when an internal failure has occurred, may be out of resources.

LV_LICENSES_EXPIRED

The license associated with the port has been invalidated.

LV_GRAMMAR_LOADING_ERROR

Either gram_name or gram_uri, or both are NULL, or gram_uri points to an invalid location.

LV_LOAD_GRAMMAR_TIMEOUT

Sending the grammar to the ASR server timed out.

LV_GRAMMAR_SYNTAX_ERROR

Either the tag-format specified in the grammar is not supported or the grammar file was not understandable to the grammar compiler.

LV_NO_SERVER_AVAILABLE

There are no ASR servers available to load and compile the grammar.

LV_ACTIVE_GRAMMAR_INVALID_LANGUAGE

The connected ASR server(s) do not support the language of the grammar being loaded.

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.

It is possible that some of the above return codes may get returned for different underlying reasons. Use LV_SRE_ReturnGrammarErrorString to obtain a description of the actual reason for failure.

C Code

  1. // This method streamlines the process of loading and activating a grammar,
  2. // making it easier to do from main.

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

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

See Also