У меня есть «Джарвис» или личный помощник в веб-браузере. Он работает на некотором коде распознавания речи. Я поставлю внизу. Я хочу сказать ему что-то в Google, затем сказать, что я хочу, чтобы Google, а затем заставить его автоматически Google для меня.
Можете ли вы помочь?
просто вы знаете, что распознавание речи работает нормально, но кнопка для его активации не показана в описании.
<script>
var x = document.getElementById("reconition");
var message = document.querySelector('#message');
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList;
var grammar = '#JSGF V1.0;'
var recognition = new SpeechRecognition();
var speechRecognitionList = new SpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;
recognition.lang = 'en-US';
recognition.interimResults = false;
recognition.onresult = function(event) {
var last = event.results.length - 1;
var command = event.results[last][0].transcript;
message.textContent = 'Voice Input: ' + command + '.';
if(command.toLowerCase() === 'google something'){
var msg = new SpeechSynthesisUtterance('what would you like for me to google');
window.speechSynthesis.speak(msg);
}
}
};
recognition.onspeechend = function() {
recognition.stop();
};
recognition.onerror = function(event) {
message.textContent = 'Error occurred in recognition: ' + event.error;
}
document.querySelector('#btnGiveCommand').addEventListener('click', function(){
recognition.start();
});