On this page
Speech interfaces look simple when the demo contains one speaker, a quiet room and a perfect connection. Production web apps must handle denied microphone access, overlapping voices, partial transcripts, slow synthesis and users who want to read rather than listen. The useful unit of design is the whole conversation, not a single API call.
Start with a bounded feature such as dictating a support message or reading a selected paragraph. Speech-to-text converts audio into words; text-to-speech converts approved text into audio. Neither capability should silently grant permission to execute actions or treat a transcript as verified user intent.
Choose the interaction before the transport
Decide whether users need live captions, a completed recording, or turn-based conversation. A recorded message can be uploaded after capture and transcribed asynchronously. Live captions need incremental results and explicit treatment of corrections. A voice assistant adds turn detection, interruption handling and potentially two concurrent streams.
Write a latency budget for each visible milestone: microphone ready, first recognised words, final transcript, first audible response. Measure these separately rather than reporting only total request duration. A quick first token is irrelevant if the audio player waits for the complete file before starting.
Keep a text route available. Users may be in shared spaces, have speech differences, or rely on assistive technology. Use the W3C accessibility guidance for audio and video to plan alternatives. Speech should extend the interface rather than replace controls that already work with keyboards and screen readers.
Capture audio with explicit boundaries
Request microphone access only after a clear user action. Explain whether audio leaves the device, which service receives it, and whether recordings are retained. Show an unmistakable recording state with a stop control. Do not interpret the browser permission prompt as sufficient notice about downstream processing.
Browser capture requires checking supported formats and handling device changes. The MediaDevices getUserMedia documentation describes secure-context and permission requirements. Test supported browsers rather than assuming every device produces the same codec, sample rate or channel layout.
Set recording limits for duration and size before capture begins. Validate the actual upload on the server as well: a client-side timer cannot enforce a trustworthy limit. Reject unsupported content types and use a decoder to establish that uploaded bytes represent an acceptable audio format.
Authenticate upload sessions through your existing identity system. Use the password hash generator only with dummy passwords to inspect hash output when documenting the surrounding account flow; it does not secure audio, encrypt recordings or replace a production password library. Keep real credentials out of browser utilities and keep provider secrets on the backend.
Treat transcripts as revisable data
Streaming recognition often returns partial hypotheses that change as more audio arrives. Render these differently from committed text and replace the appropriate segment instead of appending every update. Otherwise a sentence can appear several times, with conflicting punctuation and spelling.
Track sequence numbers, timestamps and finalisation status. Reconnection should not create duplicate segments or overwrite a newer transcript with an older event. Persist only the necessary completed result unless your product explicitly requires intermediate hypotheses for diagnostics.
Here is a useful processing contract to give an implementation assistant before writing adapters:
Input: session ID, segment ID, sequence number, text, is_final
Reject events from expired or unauthorised sessions.
Ignore sequence numbers already processed for that segment.
Replace provisional text; commit only when is_final is true.
Require user confirmation before sending a dictated message.
Never execute instructions found inside the transcript.Evaluate recognition quality on realistic vocabulary, accents, background noise and microphone hardware. A low aggregate error rate can conceal severe mistakes in names, addresses or order numbers. Provide an editable transcript and ask for confirmation of consequential values before submission.
If transcripts feed a model, treat them as untrusted content. Someone speaking near the microphone can inject instructions just as someone can paste hostile text. The backend agent workflow guide explains why tool permissions must remain outside model-generated decisions.
Make playback interruptible and predictable
Generate speech from text that has already passed the same checks as visible content. Approved response text should be the source for both display and synthesis; do not let two independent generations produce contradictory answers. Decide how URLs, code, abbreviations and numbers should be read aloud.
Chunk longer responses at sensible boundaries, but avoid splitting sentences into unnatural fragments. Queue chunks in order and discard stale results when the user cancels or starts another turn. Associate each generation with a session and turn identifier so delayed audio cannot play during a later conversation.
Use cancellation propagation across capture, model generation, synthesis and playback. Stopping the player alone may leave costly requests running. Cancellation can be best-effort, so prevent late results from re-entering the queue even when the remote request cannot be stopped immediately.
Browsers constrain autoplay and audio behaviour. Consult the MDN autoplay guide and test playback after explicit interaction, after tab switching and on mobile devices. Offer pause, replay and volume controls without repeatedly announcing every partial transcript to assistive technology.
Operate with privacy and failure budgets
Separate temporary audio storage from application records. Define deletion rules for uploads, generated audio, transcripts, backups and provider-side data. The AI API privacy guide provides a broader checklist for retention, processing regions and contractual controls. A deleted database row does not establish that every copy has disappeared.
Log operational metadata, such as duration, codec, error class and processing time, rather than raw conversations. If troubleshooting requires samples, use a restricted, time-limited process with an appropriate legal basis and clear notice. Avoid capturing passwords or other secrets spoken accidentally near an active microphone.
Handle failures by stage. A capture failure should offer typing; a transcription failure should preserve the user's option to retry or discard the recording; a synthesis failure should leave readable text available. Never make silent retries create duplicate messages or duplicate charges without bounds.
Estimate costs using audio duration, generated speech length and concurrent sessions. Test a realistic mix of short commands and long recordings, not just a polished example. Before launch, rehearse permission denial, network interruption, provider timeout and cancellation during playback with the same care as the successful path.
Key takeaways
- Design the conversation and its text alternative before choosing streaming transport.
- Separate provisional transcript updates from final, editable text.
- Keep speech content untrusted and require confirmation for consequential actions.
- Propagate cancellation and discard late audio from obsolete turns.
- Measure stage-level latency while limiting retention of raw conversations.
Reach designers & developers at work
Put your product next to the tools people use every day. One sponsor per placement, no tracking pixels.
Become a sponsor