Home
← All projects

Node.js service · Oct 2025 · Prototype

Voice AI calls

A phone agent that listens, thinks and answers in real time over a normal call.

A service that places a phone call and holds a live conversation. Speech is transcribed as it arrives, an LLM writes the reply, and a synthesised voice speaks it back down the line, with fallbacks for every provider.

One reply, end to end
caller speaks
→ Twilio media stream (WebSocket)
→ Deepgram speech-to-text
→ GPT-4o-mini writes the reply
→ ElevenLabs voice
→ ffmpeg: mp3 to 8 kHz μ-law
→ back to the caller, 40 ms at a time
  • Twilio media streams over WebSockets, both directions
  • Every stage swappable: Deepgram or Whisper, GPT-4o-mini or Groq, ElevenLabs or Play.ht
  • Fixed static on the line by transcoding speech to 8 kHz μ-law in real time

What I built

A Node.js service that bridges a phone call to AI providers in real time. Twilio streams the caller’s audio over a WebSocket. Deepgram transcribes it as it arrives, voice activity detection decides when the caller has finished, GPT-4o-mini writes a reply, and ElevenLabs speaks it. Events go out to n8n webhooks for follow-up workflows.

Each stage sits behind a provider interface, so Deepgram can fall back to Whisper, OpenAI to Groq, and ElevenLabs to Play.ht with an environment variable.

The hard part

Audio. Twilio’s stream expects raw μ-law at 8 kHz, but ElevenLabs returned MP3 even when asked for μ-law, and the caller heard static. The fix converts each reply with ffmpeg on the fly and streams it back in 320-byte, 40 ms chunks. Most of the later work went into making that conversion fast enough not to add a pause.

Where it stands

A working prototype: calls connect, transcription and replies work, and audio plays cleanly.