Browser dictation with Web Speech and MediaRecorder
web-speechspeechrecognitionmediarecordermicrophonechrome
A web page can do live speech-to-text and keep the raw audio at the same time, with no
server, by combining SpeechRecognition (Web Speech API) with MediaRecorder. Built into
the Story app (~/dev/story, July 2026), a local tool for dictating story ideas and having
Claude arrange them.
Setup
- Call
navigator.mediaDevices.getUserMedia({audio: true})first. One permission prompt then covers both the recorder and recognition. - Start a
MediaRecorderon that stream; on stop, assemble the chunks into aBloband store it (IndexedDB handles blobs well). Play takes back withURL.createObjectURL(blob). - Start recognition:
new (window.SpeechRecognition || window.webkitSpeechRecognition)()withcontinuous = true,interimResults = true,lang = navigator.language. - In
onresult, append final results to the text with sensible spacing, and show interim results separately (a "listening" bar) so they do not get committed twice.
Gotchas
- Chrome stops recognition after a stretch of silence, even with
continuous = true. Keep anactiveflag and restart inonendwhile it is set. Before an intentional stop, clear the flag (or nullonend) so it does not restart itself. - Web Speech recognition is reliable only in Chrome (it streams audio to Google's service, so it also needs a network connection). Feature-detect it; if missing, still record audio and tell the user to use Chrome.
- Microphone access requires a secure context:
https://orlocalhost. A page opened fromfile://or a LAN IP over http will not get the mic.
See also
- Zero-build web apps (vanilla JS, localStorage, single file)
- Calling Claude directly from a browser page