JavaScript 语音识别功能实现
// Html代码
Speech Recognition
Click the microphone icon and speak.
// JavaScript代码 // Get the start button const startButton = document.querySelector('.start-btn'); // Create a new speech recognition object const recognition = new SpeechRecognition(); // Set the language recognition.lang = 'en-US';
// Create an event listener for when the start button is clicked startButton.addEventListener('click', function() { // Start recognition recognition.start(); });
// Create a function to handle what happens when the recognition picks up speech recognition.onresult = function(event) { // Access the spoken phrase const current = event.resultIndex; const transcript = event.results[current][0].transcript; // Do something with the spoken phrase console.log(transcript); };
原文地址: https://www.cveoy.top/t/topic/ljYw 著作权归作者所有。请勿转载和采集!