3 ms·
If you don't mind sharing, would you explain how it is too useful for your work?
by jesterson 4y ago
If you don't mind sharing, would you explain how it is too useful for your work?
- rahimnathwani 4y agoNot GP, but I used it the other day to start a simple web app: Please write a javascript for testing pronunciation. The app should have the following features: 1. Store a static list of Chinese characters. 2. When the user clicks start, show the user a single character from the list, and wait for them to pronounce it out loud. Use the web speech API to recognize the character, and compare it with the character displayed. 3. If the characters match, repeat step 2. If not, give the user one more chance, before continuing. 4. Keep an internal record of which characters the user got right and wrong, and how many times. var characterList = ["汉", "字", "编", "程", "语", "言"]; var correctCharacters = []; var incorrectCharacters = []; var numAttempts = 0; function startTest() { var character = characterList[Math.floor(Math.random() * characterList.length)]; document.getElementById("displayCharacter").innerHTML = character; var recognition = new webkitSpeechRecognition(); recognition.onresult = function(event) { var pronunciation = event.results[0][0].transcript; if (pronunciation === character) { correctCharacters.push(character); startTest(); } else { numAttempts++; if (numAttempts < 2) { document.getElementById("prompt").innerHTML = "Incorrect. Please try again."; } else { incorrectCharacters.push(character); numAttempts = 0; startTest(); } } } recognition.start(); } document.getElementById("startButton").addEventListener("click", startTest); Give me the corresponding HTML <div id="displayCharacter"></div> <div id="prompt"></div> <button id="startButton">Start Test</button>