demo · v135

Language picker for track-bound recognition

The SpeechRecognition.lang attribute accepts any BCP-47 language tag — and it works just as well when you’re feeding a custom MediaStreamTrack as when you’re using the default mic. Pick a language, speak, and see the transcript in that language. Changing the language restarts the recogniser bound to the same track.

SpeechRecognition: ? start(track): ?

Language (SpeechRecognition.lang):

Selected: en-US (English)

the code

const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const track  = stream.getAudioTracks()[0];

const rec = new SpeechRecognition();
rec.lang             = 'fr-FR'; // any BCP-47 tag
rec.continuous       = true;
rec.interimResults   = true;
rec.start(track);               // Chrome 135+

see also