Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Python Voice Agent Example

English | 简体中文

A minimal CLI example that connects to a Voice Agent server, prints live transcript events, and reads remote audio using the Python SDK with aiortc.

Prerequisites

  • Python 3.10+
  • (Optional but recommended) a virtual environment
  • A running Voice Agent server (see root README)

Setup

cd examples/python

# Create a virtual environment (recommended)
python -m venv .venv
source .venv/bin/activate   # macOS/Linux
# .venv\Scripts\activate    # Windows

# Install the SDK and dependencies
pip install -r requirements.txt

Run

1. Gradio Web UI

python main.py

This will launch a local web server at http://127.0.0.1:7860. It provides a rich graphical interface with a conversational chatbot view, using browser WebRTC for microphone and speaker access with native Acoustic Echo Cancellation.

2. Terminal CLI

python cli.py

# Or with a custom WHIP endpoint
WHIP_URL=http://your-server:8080/whip python cli.py

This runs a lightweight script entirely within your terminal, identical in architecture to the Go and Rust examples. It prints transcripts directly to standard output as you speak.

Environment Variables

Variable Default Description
WHIP_URL http://localhost:8080/whip WHIP signaling endpoint
TOKEN_URL Token endpoint URL (e.g. http://localhost:8080/token). Required when the server has JWT auth enabled.
API_KEY API key sent as Bearer header when fetching a token from TOKEN_URL.

JWT Authentication

When the server has jwt_secret set, all /whip requests require a valid JWT:

TOKEN_URL=http://localhost:8080/token API_KEY=sk-streamcore-demo-key python cli.py

What It Does

  1. Connects to the Voice Agent server via WebRTC + WHIP signaling.
  2. Uses FastRTC behind the scenes to capture your local microphone through the browser securely.
  3. Uses FastRTC to stream the agent's remote audio track directly to your browser's WebRTC engine automatically.
  4. Benefits natively from the browser's built-in Acoustic Echo Cancellation (AEC) and hardware Noise Suppression.
  5. Displays connection status changes and live transcripts via a browser chatbot in main.py (or prints them locally in cli.py).

Extending

  • Pass an aiortc MediaStreamTrack to client.connect(track) to send microphone audio
  • Access client.remote_track after connection to process the agent's audio
  • Use client.transcript to access the full conversation history