Speech recognition using the JavaScript API

You can use the native JavaScript API (webitSpeechRecognition()) to recognize voice recorded from your computer or mobile device.

Example:

javascript
var recognition = new window.webkitSpeechRecognition()

// Set the language, I've chosen Thai for this example
recognition.lang = 'th-TH'

Now you can set the buttons to start and stop recording:

html
<button onclick = "iniSpeech()">Start</button>
<button onclick = "endSpeech()">Stop</button>

And here are the functions:

javascript
function iniSpeech(){

    recognition.onresult = e => {
        
        var transcript = e.results[0][0].transcript

        console.log(transcript)

    }

    recognition.start()


}

function endSpeech(){

    recognition.stop()

}

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.