Twilio Media Streams with Giggy WebSocket STT

Twilio Media Streams delivers 8 kHz G.711 mu-law payloads over WebSockets. By decoding mu-law bytes to 8 kHz LINEAR16 PCM in memory (a 256-entry lookup table, no ffmpeg or resampling), you can stream live calls straight to wss://api.giggy.ai/v1/audio/transcriptions for $0.08 per audio hour in 27 languages.

Before you start

Create it in Giggy

  1. Accept the Twilio Media Streams WebSocket connection and wait for the Twilio "start" event.
  2. Open an authenticated upstream WebSocket to wss://api.giggy.ai/v1/audio/transcriptions with xi-api-key: $GIGGY_API_KEY.
  3. Send the Giggy start message specifying 8000 Hz LINEAR16 and an optional ISO language code (such as en or de).
  4. For each Twilio "media" event, base64-decode media.payload, convert mu-law bytes to signed 16-bit little-endian PCM via a lookup table, and forward the binary buffer to Giggy.
  5. Consume cumulative transcript_chunk events from Giggy and send the stop/input_complete signal when Twilio sends its "stop" event.

Improve the result

Examples

Common mistakes

Related guides

Open Speech API · Creative app · Account guides