# Realtime Voice Agent (pt-BR)

> Streaming voice-agent pipeline for Brazilian Portuguese: Deepgram STT, Claude with tool calling and ElevenLabs TTS over WebSocket, with barge-in and per-turn latency metrics. Offline test suite included; live latency is not benchmarked yet.

Realtime Voice Agent (pt-BR) is a free AI agent skill on Agensi by Rafael Prado, in Agents & Orchestration. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Rafael Prado](https://www.agensi.io/creators/rafael-prado)
- Category: [Agents & Orchestration](https://www.agensi.io/skills/agents-orchestration)
- Version: 1.0
- Last updated: 2026-11-18
- Security: scan passed (2026-11-18); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/realtime-voice-agent-pt-br
- Tags: ai-agents, python, fastapi, web-sockets, deepgram, elevenlabs

## About this skill

A reusable, open-source (MIT) pipeline for building real-time voice agents in Brazilian Portuguese. It extracts the orchestration layer of a working clinic-receptionist demo into a module you can point at your own tools and prompt.

### What it does
- **End-to-end streaming:** microphone audio goes over a WebSocket to Deepgram Nova-3, the transcript goes to Claude (streaming, with tool calling), and the answer is spoken by ElevenLabs while it is still being generated.
- **Barge-in:** if the user talks over the agent, the LLM call, the TTS stream and the browser player are all cancelled, and the interrupted sentence is kept in the history as interrupted.
- **Sentence chunking:** LLM tokens are cut into sentences for incremental TTS. The first chunk may break at a comma to start speaking earlier; abbreviations such as "Dra." and numbers such as "1.500" are handled.
- **Atomic tool rounds:** a tool_use and its tool_result are written to the history together, so an interruption never leaves an invalid conversation.
- **Filler phrase:** a short "let me check" phrase is spoken while a tool runs.
- **Per-turn metrics:** endpointing, first LLM token, first sentence, first TTS audio and voice-to-voice, measured on the audio clock.
- **Swappable providers:** Deepgram, Claude and ElevenLabs sit behind small interfaces, so you can replace any of them.

### How to use it
1. Install the requirements and run `pytest -q` (offline, no keys needed).
2. Copy `.env.example` to `.env` and add your own Anthropic, Deepgram and ElevenLabs keys.
3. Implement your tools as an object with `run(name, args)` and a tool schema in Messages API format, then adapt the voice prompt (see `examples/server.py`).
4. Run `uvicorn examples.server:app --reload`. The WebSocket protocol and the browser audio worklets (`static/worklets.js`) are documented in `SKILL.md`.

### Honest status
The 6 tests run offline with fake providers (sentence chunking, a full turn with a tool call, barge-in). This package has not been benchmarked against the live APIs yet, so the sub-1.5 s voice-to-voice figure is a design target, not a measured result. `SKILL.md` explains how to measure it on your own setup.

### Requirements
Python 3.11+, your own API keys for Anthropic, Deepgram and ElevenLabs, and headphones to test barge-in.

### Not included
SIP/phone-line integration, multi-speaker handling, and the full browser UI of the original demo. Voice quality and latency depend on your network and your providers.

## Requires

- Python 3.11+
- Anthropic API key
- Deepgram API key
- ElevenLabs API key

## Known limitations

Not benchmarked against the live APIs; the sub-1.5 s voice-to-voice figure is a design target. Offline tests use fake providers. Requires Python 3.11+ and your own Anthropic, Deepgram and ElevenLabs keys. No SIP/PSTN, no multi-speaker handling, and the full browser UI of the original demo is not included (only the audio worklets and the WebSocket protocol).

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Realtime Voice Agent (pt-BR) skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How is this different from just prompting an LLM for voice?

A prompt alone does not handle streaming microphone audio, end-of-turn detection, sentence-by-sentence TTS or interruptions. This module provides that orchestration around the LLM. It does not make the model itself faster or smarter.

### Can I use it for languages other than Portuguese?

Possibly, but it was built and is documented for pt-BR only and has not been tested in other languages. You would change DEEPGRAM_LANGUAGE, the language_code in providers/elevenlabs_tts.py (currently "pt"), the voice id and the prompt. The sentence chunker's abbreviation list is also Portuguese-specific.

### What accounts and API keys do I need?

Your own keys for Anthropic, Deepgram and ElevenLabs, billed by those providers. The offline test suite (pytest -q) needs no keys.

### Can the agent call my own APIs or databases?

Yes. You provide an object with a synchronous run(name, args) method and a tool schema in Messages API format. Keep run() fast so the tool_use and tool_result are written to the history atomically. For slow remote calls, SKILL.md describes the asyncio.to_thread plus shield approach.

### Has the latency been measured?

No. Under 1.5 s voice-to-voice is a design target, not a measured result, and the package has not been benchmarked against the live APIs. Each turn emits a metrics event, and SKILL.md explains how to measure median and p95 on your own setup.

### Does it connect to a phone line (SIP/PSTN)?

No. It streams browser audio over a WebSocket (PCM16, 16 kHz in and 24 kHz out). Telephony would need a bridge that converts the audio format, which is not included.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
