Build real-time conversational AI voice engines using async worker pipelines, streaming transcription, LLM agents, and TTS synthesis with interrupt handling and multi-provider support
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Build real-time conversational AI voice engines using async worker pipelines, streaming transcription, LLM agents, and TTS synthesis with interrupt handling and multi-provider support
type
skill
created
2026-02-27T00:00:00.000Z
domain
ai-ml
category
nlp
risk
unknown
source
community
tags
["skill","ai-ml","nlp","voice","engine"]
Voice AI Engine Development
Overview
This skill guides you through building production-ready voice AI engines with real-time conversation capabilities. Voice AI engines enable natural, bidirectional conversations between users and AI agents through streaming audio processing, speech-to-text transcription, LLM-powered responses, and text-to-speech synthesis.
The core architecture uses an async queue-based worker pipeline where each component runs independently and communicates via asyncio.Queue objects, enabling concurrent processing, interrupt handling, and real-time streaming at every stage.
When to Use This Skill
Use this skill when:
Building real-time voice conversation systems
Implementing voice assistants or chatbots
Creating voice-enabled customer service agents
Developing voice AI applications with interrupt capabilities
Integrating multiple transcription, LLM, or TTS providers
Working with streaming audio processing pipelines
The user mentions Vocode, voice engines, or conversational AI
Core Architecture Principles
The Worker Pipeline Pattern
Every voice AI engine follows this pipeline:
Audio In → Transcriber → Agent → Synthesizer → Audio Out
(Worker 1) (Worker 2) (Worker 3)
Key Benefits:
Decoupling: Workers only know about their input/output queues
Concurrency: All workers run simultaneously via asyncio
asyncdefsend_speech_to_output(self, synthesis_result, stop_event, ...):
asyncfor chunk_result in synthesis_result.chunk_generator:
# Check stop_event (this is the interruption_event)if stop_event.is_set():
logger.debug("Interrupted! Stopping speech.")
# Calculate what was actually spoken
seconds_spoken = chunk_idx * seconds_per_chunk
partial_message = synthesis_result.get_message_up_to(seconds_spoken)
# e.g., "I think the weather will be nice today"return partial_message, True# cut_off = True
Step 4: Agent updates history
if cut_off:
# Update conversation history with partial messageself.agent.update_last_bot_message_on_cut_off(message_sent)
# History now shows:# Bot: "I think the weather will be nice today" (incomplete)
InterruptibleEvent Pattern
Every event in the pipeline is wrapped in an InterruptibleEvent:
classInterruptibleEvent:
def__init__(self, payload, is_interruptible=True):
self.payload = payload
self.is_interruptible = is_interruptible
self.interruption_event = threading.Event() # Initially not setself.interrupted = Falsedefinterrupt(self) -> bool:
"""Interrupt this event"""ifnotself.is_interruptible:
returnFalseifnotself.interrupted:
self.interruption_event.set() # Signal to stop!self.interrupted = TruereturnTruereturnFalsedefis_interrupted(self) -> bool:
returnself.interruption_event.is_set()
Multi-Provider Factory Pattern
Support multiple providers with a factory pattern:
asyncdefterminate(self):
"""Gracefully shut down all workers"""self.active = False# Stop all workersself.transcriber.terminate()
self.agent.terminate()
self.synthesizer.terminate()
# Wait for queues to drainawait asyncio.sleep(0.5)
# Close connectionsifself.websocket:
awaitself.websocket.close()
asyncdeftest_full_pipeline():
# Create all components
conversation = create_test_conversation()
# Send test audio
conversation.receive_audio(test_audio_chunk)
# Wait for response
response = await wait_for_audio_output(timeout=5)
assert response isnotNone
3. Test Interrupts
asyncdeftest_interrupt():
conversation = create_test_conversation()
# Start bot speakingawait conversation.agent.generate_response("Tell me a long story")
# Interrupt mid-responseawait asyncio.sleep(1) # Let it speak for 1 second
conversation.broadcast_interrupt()
# Verify partial message in transcript
last_message = conversation.transcript.event_logs[-1]
assert last_message.text != full_expected_message
Implementation Workflow
When implementing a voice AI engine:
Start with Base Workers: Implement the base worker pattern first
Add Transcriber: Choose a provider and implement streaming transcription
Add Agent: Implement LLM integration with streaming responses
Add Synthesizer: Implement TTS with audio streaming
Connect Pipeline: Wire all workers together with queues
Add Interrupts: Implement the interrupt system
Add WebSocket: Create WebSocket endpoint for client communication
Test Components: Unit test each worker in isolation
Test Integration: Test the full pipeline end-to-end
Add Error Handling: Implement robust error handling and logging
Optimize: Add rate limiting, monitoring, and performance optimizations
Related Skills
@websocket-patterns - For WebSocket implementation details
@async-python - For asyncio and async patterns
@streaming-apis - For streaming API integration
@audio-processing - For audio format conversion and processing
@systematic-debugging - For debugging complex async pipelines
Resources
Libraries:
asyncio - Async programming
websockets - WebSocket client/server
FastAPI - WebSocket server framework
pydub - Audio manipulation
numpy - Audio data processing
API Providers:
Transcription: Deepgram, AssemblyAI, Azure Speech, Google Cloud Speech
LLM: OpenAI, Google Gemini, Anthropic Claude
TTS: ElevenLabs, Azure TTS, Google Cloud TTS, Amazon Polly, Play.ht
Summary
Building a voice AI engine requires:
✅ Async worker pipeline for concurrent processing
✅ Queue-based communication between components
✅ Streaming at every stage (transcription, LLM, synthesis)
✅ Interrupt system for natural conversations
✅ Rate limiting for real-time audio playback
✅ Multi-provider support for flexibility
✅ Proper error handling and graceful shutdown
The key insight: Everything must stream and everything must be interruptible for natural, real-time conversations.