Skip to main content
This recipe shows the moving pieces for browser microphone transcription. In production, combine it with Browser WebSockets so the browser uses a short-lived token instead of an API key.

Flow

  1. Ask the user for microphone permission.
  2. Capture audio with the Web Audio API.
  3. Convert float samples to 16-bit mono PCM.
  4. Send base64 audio chunks over wss://api.gradium.ai/api/speech/asr.
  5. Render text messages and use step messages for turn-taking.

Browser Client

ScriptProcessorNode is easy to read but deprecated. For production, prefer an AudioWorklet so audio capture stays reliable under UI load.

Audio Format Notes

  • input_format: "pcm" means 24 kHz, 16-bit signed mono PCM.
  • If your browser audio graph runs at 48 kHz, either resample to 24 kHz or send input_format: "pcm_48000".
  • Send small chunks, around 80-100 ms, to keep latency low.
  • Do not send compressed browser formats unless you explicitly set a supported Gradium input format such as opus.

Speech-to-Text WebSocket

Message types, VAD, flushing, and direct WebSocket examples.

Turn-taking with VAD

Use semantic VAD to decide when a speaker has finished.