A complete voice interaction example using the OpenAI Agents SDK with pre-recorded audio input. This demonstrates the basic voice pipeline workflow with speech-to-text, agent processing, and text-to-speech capabilities.
Sign in to save downloads to your library and vote.
Preview
ποΈ Static Voice Agent
A complete voice interaction example using the OpenAI Agents SDK with pre-recorded audio input. This demonstrates the basic voice pipeline workflow with speech-to-text, agent processing, and text-to-speech capabilities.
π― What This Demonstrates
- Static Audio Processing: Record once, process completely
- Voice Pipeline: Complete speech-to-text β agent β text-to-speech workflow
- Multi-Agent System: Agent handoffs based on language detection
- Tool Integration: Voice-activated tools for weather, time, and calculations
- Audio Management: Recording, playback, and audio utility functions
π§ Core Concept: Static Voice Pipeline
The static voice pipeline processes a complete audio recording in one workflow. Think of it as a turn-based voice assistant that:
- Records your complete message first
- Transcribes the entire audio to text
- Processes with AI agents and tools
- Converts the complete response back to speech
- Plays the full audio response
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STATIC VOICE WORKFLOW β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β π€ RECORD AUDIO |
β β β
β βΌ β
β βββββββββββββββ 1. COMPLETE RECORDING β
β β AUDIO β β¦ Record for fixed duration β
β β CAPTURE β β¦ Full audio buffer β
β βββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββ 2. SPEECH-TO-TEXT β
β β TRANSCRIBE β β¦ Convert full audio to text β
β β AUDIO β β¦ Complete transcription β
β βββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββ 3. AGENT PROCESSING β
β β AGENT β β¦ Multi-agent workflow β
β β WORKFLOW β β¦ Tool calls & handoffs β
β βββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββ 4. TEXT-TO-SPEECH β
β β GENERATE β β¦ Convert response to audio β
β β SPEECH β β¦ Stream audio output β
β βββββββββββββββ β
β β β
β βΌ β
β π PLAY RESPONSE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Quick Start
-
Install voice dependencies:
pip install 'openai-agents[voice]' pip install sounddevice numpy soundfile librosa -
Set up environment:
cp env.example .env # Edit .env and add your OpenAI API key -
Run the static voice agent:
python agent.py
π§ͺ What This Example Includes
Multi-Language Support
- English Agent: Primary assistant with all tools
- Spanish Agent: Specialized Spanish-speaking agent
- French Agent: Specialized French-speaking agent
- Automatic Language Detection: Handoffs based on detected language
Voice-Activated Tools
get_weather(city): Get weather information for any cityget_time(): Get current timecalculate_tip(bill, percentage): Calculate tips for bills
Audio Utilities
AudioPlayer: Real-time audio playback with sounddevicerecord_audio(): Microphone recording with duration controlcreate_silence(): Generate silence bufferssave_audio()/load_audio(): Audio file operations
Workflow Callbacks
WorkflowCallbacks: Monitor transcription, tool calls, and handoffs- Debug output for pipeline monitoring
- Performance tracking and statistics
π― Example Interactions
English Examples
- "Tell me a joke" β Agent responds with humor
- "What's the weather in Tokyo?" β Calls weather tool
- "What time is it?" β Calls time tool
- "Calculate a 20% tip on a $50 bill" β Performs calculation
Language Handoffs
- "Hola, ΒΏcΓ³mo estΓ‘s?" β Handoff to Spanish agent
- "Bonjour, comment allez-vous?" β Handoff to French agent
- Agents respond in the detected language
Tool Integration
- Weather queries work in any language
- Time and calculation tools available to all agents
- Tools called automatically based on user requests
π§ Key Implementation Patterns
1. Voice Pipeline Setup
pipeline = VoicePipeline(
workflow=SingleAgentVoiceWorkflow(agent, callbacks=WorkflowCallbacks())
)
2. Audio Input Processing
audio_buffer = record_audio(duration=5.0)
audio_input = AudioInput(buffer=audio_buffer)
result = await pipeline.run(audio_input)
3. Audio Output Streaming
with AudioPlayer() as player:
async for event in result.stream():
if event.type == "voice_stream_event_audio":
player.add_audio(event.data)
4. Multi-Agent Configuration
agent = Agent(
name="Assistant",
handoffs=[spanish_agent, french_agent],
tools=[get_weather, get_time, calculate_tip]
)
π‘ Voice Agent Best Practices
- Clear Audio Recording: Ensure good microphone quality and minimal background noise
- Concise Instructions: Voice interactions work best with brief, clear agent instructions
- Error Handling: Implement robust error handling for audio recording failures
- Language Detection: Use prompt engineering for automatic language switching
- Tool Design: Design tools for voice interaction with conversational responses
π Performance Characteristics
Static Pipeline Benefits
- Predictable Processing: Fixed recording duration
- Complete Context: Full utterance available for processing
- Simpler Implementation: No real-time complexity
- Better for Complex Queries: Can process longer, detailed requests
Use Cases
- Voice Assistants: Traditional turn-based interaction
- Voice Commands: Specific task automation
- Language Learning: Practice with multilingual agents
- Accessibility: Voice interface for applications
π¨ Requirements & Dependencies
Core Dependencies
openai-agents[voice]: OpenAI Agents SDK with voice supportsounddevice: Audio recording and playbacknumpy: Audio data processingsoundfile: Audio file operations (optional)librosa: Audio resampling (optional)
System Requirements
- Microphone: For audio input
- Speakers/Headphones: For audio output
- Python 3.8+: Required for async support
π Related Examples
- Streaming Voice: Real-time voice interaction
- Voice Pipeline Documentation: Official pipeline docs
- Voice Quickstart: Basic voice setup
π οΈ Customization Options
Extend Audio Utilities
- Add audio effects and filtering
- Implement custom audio formats
- Add audio visualization
Enhance Agent Capabilities
- Add more specialized language agents
- Implement domain-specific tools
- Add conversation memory
Improve Voice Experience
- Add voice activity detection
- Implement custom wake words
- Add voice emotion detection
π‘ Pro Tips
- Test Audio Setup: Verify microphone and speakers before running
- Experiment with Duration: Adjust recording duration based on use case
- Monitor Debug Output: Use callbacks to understand pipeline behavior
- Handle Interruptions: Implement graceful handling of Ctrl+C
- Optimize for Voice: Keep agent responses concise and conversational
π Next Steps
After mastering static voice agents:
- Streaming Voice: Implement real-time voice interaction
- Advanced Voice Pipelines: Custom pipeline configurations
- Production Voice Apps: Deploy voice agents in real applications
Ingestion metadata
- Source catalog
- awesome-llm-apps
- Repository
- Shubhamsaboo/awesome-llm-apps Β· main
- File path
- ai_agent_framework_crash_course/openai_sdk_crash_course/11_voice/static/README.md
- Last refreshed
- 7/24/2026, 3:00:13 AM (51m ago)
- Refresh schedule
- Daily Β· 03:00 UTC
- Dedupe status
- Unique Β· deduped by (source, url)