webkitSpeechGrammarList()真的有用吗?

时间:2015-11-26 16:20:37

标签: javascript webspeech-api google-speech-api

我正在尝试实施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.';
}

所以,因为这是所有实验技术。我想知道..这真的实现了吗?我怎么知道?

1 个答案:

答案 0 :(得分:3)

此时语法为ignored