examples/agent/realtime_voice_agent/README.md
This example demonstrates how to build a real-time voice conversation agent using AgentScope's RealtimeAgent. The agent supports bidirectional voice streaming, enabling natural voice conversations with low latency and real-time audio transcription.
DASHSCOPE_API_KEYInstall the required packages:
uv pip install agentscope fastapi uvicorn websockets
# or
# pip install agentscope
Run the FastAPI server:
cd examples/agent/realtime_voice_agent
python run_server.py
The server will start on http://localhost:8000 by default.
Open your web browser and navigate to:
http://localhost:8000
You will see a web interface with:
Configure the Agent (optional):
Start Voice Recording:
Stop Recording:
Video Recording (Optional):
AgentScope supports multiple realtime voice models. By default, this example uses DashScope's qwen3-omni-flash-realtime model, but you can easily switch to other providers.
Edit run_server.py and replace the model initialization code:
For OpenAI:
from agentscope.realtime import OpenAIRealtimeModel
agent = RealtimeAgent(
name="Friday",
sys_prompt=sys_prompt,
model=OpenAIRealtimeModel(
model_name="gpt-4o-realtime-preview",
api_key=os.getenv("OPENAI_API_KEY"),
voice="alloy", # Options: "alloy", "echo", "marin", "cedar"
),
)
For Gemini:
from agentscope.realtime import GeminiRealtimeModel
agent = RealtimeAgent(
name="Friday",
sys_prompt=sys_prompt,
model=GeminiRealtimeModel(
model_name="gemini-2.5-flash-native-audio-preview-09-2025",
api_key=os.getenv("GEMINI_API_KEY"),
voice="Puck", # Options: "Puck", "Charon", "Kore", "Fenrir"
),
)
Don't forget to set the corresponding API key environment variable before starting the server!