webkitSpeechGrammarList() 真的有效吗?
webkitSpeechGrammarList() really works?
我正在尝试实施 webkitSpeechGrammarList。就像你在下面看到的那样。但是当我说出一个不在我 grammar
范围内的词时,我将得到结果而不是 "I didnt recognise that color"
。
var 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 ;'
var recognition = new webkitSpeechRecognition();
var speechRecognitionList = new webkitSpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;
//recognition.continuous = false;
recognition.lang = 'en-US';
recognition.interimResults = false;
recognition.maxAlternatives = 1;
var diagnostic = document.querySelector('.output');
var bg = document.querySelector('html');
recognition.start();
recognition.onresult = function(event) {
var color = event.results[0][0].transcript;
diagnostic.textContent = 'Result received: ' + color + '.';
bg.style.backgroundColor = color;
}
recognition.onspeechend = function() {
recognition.stop();
}
recognition.onnomatch = function(event) {
diagnostic.textContent = 'I didnt recognise that color.';
}
所以,因为这都是实验技术。我在想..这真的实现了吗?我怎么知道?
目前语法是ignored。
我正在尝试实施 webkitSpeechGrammarList。就像你在下面看到的那样。但是当我说出一个不在我 grammar
范围内的词时,我将得到结果而不是 "I didnt recognise that color"
。
var 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 ;'
var recognition = new webkitSpeechRecognition();
var speechRecognitionList = new webkitSpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;
//recognition.continuous = false;
recognition.lang = 'en-US';
recognition.interimResults = false;
recognition.maxAlternatives = 1;
var diagnostic = document.querySelector('.output');
var bg = document.querySelector('html');
recognition.start();
recognition.onresult = function(event) {
var color = event.results[0][0].transcript;
diagnostic.textContent = 'Result received: ' + color + '.';
bg.style.backgroundColor = color;
}
recognition.onspeechend = function() {
recognition.stop();
}
recognition.onnomatch = function(event) {
diagnostic.textContent = 'I didnt recognise that color.';
}
所以,因为这都是实验技术。我在想..这真的实现了吗?我怎么知道?
目前语法是ignored。