Speech-to-Text in the Browser
Browser Speech-to-Text
Use the Web Speech API for live speech-to-text in the browser, displaying the result and handling errors.
Educational content in the form of a scientific draft that needs expert review before being adopted as an academic reference. No experimental result that was not actually run is shown here.
Prerequisites
- A browser that supports SpeechRecognition
- Microphone
- Understand that processing may take place at an external provider depending on the browser
Tools
- speech-to-text
- audio-recorder
- wer-cer-calculator
Implementation Steps
- Check that the browser supports the API
- Create the recognition object and set the language
- Enable interim results
- Handle the onresult event and display the text
- Handle errors and the end of the session
- Compare the text with a written reference and compute WER
Code
const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
if (!SR) { console.log('not supported'); }
else {
const rec = new SR();
rec.lang = 'ar-SA';
rec.interimResults = true;
rec.onresult = e => {
const r = e.results[e.results.length - 1];
console.log(r[0].transcript, r.isFinal);
};
rec.onerror = e => console.log('error', e.error);
rec.start();
}Expected Results
Text quality is expected to vary by browser, provider and the selected language, and comparison across browsers is not possible without a shared test set.
These are educational expectations and not experimental results actually measured.
Project Tests
- Test several sentences with a written reference and compute WER and CER
- Try the same language with and without noise
- Verify that permission denial and network loss are handled
Algorithms
Experiments
References
- Web Speech API - Web APIs | MDN. MDN Web Docs. Source
Audio processing in the experiments takes place inside your browser. Audio, texts, and conversations are not saved on the server. Privacy Policy
