Voice Integration
Enable natural voice interactions with your AI agents using Voxin's advanced voice synthesis and recognition capabilities. This guide covers everything from basic voice configuration to advanced streaming features.
Voice Configuration
Configure your agent's voice characteristics using VoiceConfig:
voice_config.py
1234567891011121314
from voxin import VoiceConfig, Agentvoice_config = VoiceConfig( voice_id="clara-v1", # Choose from available voices language="en-US", # Language code speaking_rate=1.1, # Speed of speech (0.5 to 2.0) pitch=1.0, # Voice pitch (-10 to 10) volume_gain_db=1.0 # Volume adjustment (-10 to 10))agent = Agent( name="Customer Support", voice_config=voice_config)
Available Voice Options
- clara-v1: Professional female voice
- james-v1: Professional male voice
- sophie-v1: Young female voice
- alex-v1: Young male voice
Real-time Voice Recognition
Implement real-time voice recognition with noise reduction and echo cancellation:
voice_recognition.py
12345678910111213141516
from voxin import AudioConfig# Configure voice recognitionaudio_config = AudioConfig( sample_rate_hz=16000, noise_reduction=True, echo_cancellation=True, auto_gain_control=True)# Enable real-time voice recognition@agent.on_voice_input(audio_config=audio_config)async def handle_voice(audio_input): text = await agent.transcribe(audio_input) response = await agent.process(text) await agent.speak(response)
Streaming Responses
Handle real-time streaming voice responses for more natural conversations:
streaming.py
12345678910
@agent.on_messageasync def handle_voice_stream(message): # Stream real-time voice responses async with agent.streaming_response(message) as stream: async for chunk in stream: if chunk.is_final: await agent.speak(chunk.text) else: # Handle interim results print(f"Interim: {chunk.text}")
Best Practices
- ✓ Initialize voice configurations at agent startup
- ✓ Use streaming responses for real-time interactions
- ✓ Implement proper error handling for audio devices
- ✓ Consider environment noise in voice recognition settings
- ✓ Test voice interactions in various acoustic conditions