Build an AI agent that can listen to audio and speak responses using the Vercel AI SDK's ToolLoopAgent with Deepgram STT and TTS as callable tools. The agent autonomously decides when to transcribe audio and when to speak, enabling multi-step voice-driven workflows.
A Node.js agent that receives an audio URL, transcribes it using Deepgram nova-3 (via @ai-sdk/deepgram), reasons about the content using an LLM, and speaks a summary back using Deepgram Aura 2 TTS — all orchestrated by the Vercel AI SDK's agent framework.
- Node.js >= 18
- Deepgram account — get a free API key
- OpenAI account — get an API key
| Variable | Where to find it |
|---|---|
DEEPGRAM_API_KEY |
Deepgram console |
OPENAI_API_KEY |
OpenAI platform → API keys |
cp .env.example .env
# Fill in your API keys in .env
pnpm install
pnpm start| Parameter | Value | Description |
|---|---|---|
model (STT) |
nova-3 |
Deepgram's latest speech-to-text model, used via @ai-sdk/deepgram |
model (TTS) |
aura-2-helena-en |
Natural-sounding female English voice for text-to-speech |
model (LLM) |
gpt-4o-mini |
OpenAI model for the agent's reasoning (swappable via AI SDK) |
smart_format |
true |
Adds punctuation and number formatting to transcripts |
encoding |
linear16 |
Raw PCM output for TTS — easy to inspect and pipe |
sample_rate |
24000 |
24 kHz audio output for TTS |
- Agent initialisation — A
ToolLoopAgentis created with two Deepgram-powered tools (transcribeAudioandspeakText) and an LLM for reasoning. - Tool: transcribeAudio — When the agent needs to understand audio, it calls this tool which uses
@ai-sdk/deepgram'stranscribe()with Deepgram nova-3. - LLM reasoning — The agent processes the transcript, extracts key points, and decides what to say.
- Tool: speakText — The agent calls this tool to convert its response to speech using
@ai-sdk/deepgram'sgenerateSpeech()with Deepgram Aura 2. - Output — The agent returns both a written summary and the spoken audio file.
The AI SDK's tool loop means the agent autonomously decides the order and frequency of tool calls — it might transcribe multiple audio files, or speak multiple responses, without any hardcoded workflow.