xxxxxxxxxx
31
let speechRecognition;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
}
function mouseClicked() {
setupSpeechRecognition(); // this needs to happen in response to user input
speechRecognition.abort(); // stop any outstanding requests
speechRecognition.start(); // start recognition
}
function setupSpeechRecognition() {
if (speechRecognition)
return; // already set up
let SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
speechRecognition = new SpeechRecognition();
speechRecognition.lang = "en-US"; // try zh-CN
speechRecognition.continuous = false;
speechRecognition.interimResults = false;
speechRecognition.onresult = gotRecognitionResult;
}
function gotRecognitionResult(event) {
console.log(event.results[0][0].transcript);
}