Velocity API: voice.loadgrammars

Version 3

    Return To Index

    Voice.loadGrammars()

    Overview

    Tells the engine to listen for the terms in a grammar. After a grammar is loaded, the engine will try to match speech with the terms in the grammar file until the grammar is unloaded. You can have more than one grammar active at a time, so this function does not unload active grammars – it only adds to the list of active grammars. Use Voice.unloadGrammars() to unload a specific grammar file, or Voice.clearGrammars() to unload all active grammar files.

    Added in version 1.2.104

    Use Cases

    • You want to add terms for the engine to listen for.

    Remarks

    You cannot load or unload grammars that handle the default voice-enabled shortcuts in context menus. They are loaded by default.

    If you attempt to load a grammar that is already active, the engine will ignore the request.

    Limiting the number of grammars produces better speech-to-text results, so Wavelink recommends not having more than 4 grammar files active at a time.

    Format

     

    Voice.loadGrammars(grammar);
    ParameterDescriptionTypeRequiredNotes
    grammarFile name of a BNF resource.StringRequiredTo remove more than one grammar at a time, separate the names with a comma. You do not need to specify the file extension.

     

    Example 1

    /* Loading a grammar for a field/template scope 
    */

    Voice.loadGrammars('connected_digits');
    // register an anonymous event handler that will be called when the current scope is exited
    WLEvent.onExitScope(function(){ Voice.unloadGrammars('connected_digits'); });

    Example 2

    /* Loading several grammars 
    */
      
    Voice.loadGrammars('connected_digits', 'yes_no');