The addFromURI()
method of the SpeechGrammarList
interface takes a grammar present at a specific URI and adds it to the SpeechGrammarList
as a new SpeechGrammar
object.
Note that some speech recognition services may support built-in grammars that can be specified by URI.
addFromURI(src)
addFromURI(src, weight)
const grammar =
"#JSGF V1.0; grammar colors; public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghostwhite | gold | goldenrod | gray | green | indigo | ivory | khaki | lavender | lime | linen | magenta | maroon | moccasin | navy | olive | orange | orchid | peru | pink | plum | purple | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow ;";
const recognition = new SpeechRecognition();
const speechRecognitionList = new SpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;
speechRecognitionList.addFromURI("http://www.example.com/grammar.txt");