mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-27 04:49:47 +01:00
- Curated guides under docs/; trim China-only integration docs and screenshots - Root and main README set aligned with westernized product positioning - LICENSE text update where applicable
14 KiB
14 KiB
🎤 Voice Interaction
Xiaozhi's voice interaction system enables natural conversations with your ESP32 devices. This guide covers how voice recognition, language processing, and speech synthesis work together to create seamless voice experiences.
🎯 How Voice Interaction Works
Voice Processing Pipeline
graph TB
A[ESP32 Device] -->|Audio Stream| B[Voice Activity Detection]
B -->|Speech Detected| C[Speech Recognition]
C -->|Text| D[Language Processing]
D -->|Response| E[Text-to-Speech]
E -->|Audio| A
F[Wake Word] --> B
G[ASR Provider] --> C
H[LLM Provider] --> D
I[TTS Provider] --> E
Processing Steps
- 🎤 Audio Capture: ESP32 captures audio from microphone
- 🔍 Voice Activity Detection: Detects when speech starts/stops
- 📝 Speech Recognition: Converts speech to text
- 🧠 Language Processing: Understands intent and generates response
- 🔊 Speech Synthesis: Converts response to audio
- 📡 Audio Output: ESP32 plays synthesized speech
🔍 Voice Activity Detection (VAD)
What is VAD?
Voice Activity Detection determines when someone is speaking, filtering out background noise and silence. This improves accuracy and reduces unnecessary processing.
VAD Providers
SileroVAD (Default)
VAD:
SileroVAD:
type: silero_vad
model_path: models/silero_vad.jit
threshold: 0.5
min_speech_duration: 0.25
min_silence_duration: 0.5
Features:
- High accuracy speech detection
- Low latency processing
- Noise robust performance
- Free and open source
WebRTC VAD
VAD:
WebRTCVAD:
type: webrtc_vad
mode: 2
sample_rate: 16000
frame_duration: 30
Features:
- Lightweight processing
- Real-time performance
- Configurable sensitivity
- Free implementation
VAD Configuration
# VAD settings
vad:
enabled: true
provider: SileroVAD
sensitivity: 0.5 # 0.0 = most sensitive, 1.0 = least sensitive
min_speech_ms: 250 # Minimum speech duration
min_silence_ms: 500 # Minimum silence duration
pre_padding_ms: 100 # Audio before speech
post_padding_ms: 100 # Audio after speech
📝 Speech Recognition (ASR)
ASR Providers
WhisperASR (Recommended)
ASR:
WhisperASR:
type: whisper
model_name: base # tiny, base, small, medium, large
device: auto # auto, cpu, cuda
language: null # null for auto-detect
temperature: 0.0
compression_ratio_threshold: 2.4
logprob_threshold: -1.0
no_speech_threshold: 0.6
Model Comparison:
| Model | Size | Speed | Accuracy | Use Case |
|---|---|---|---|---|
| tiny | 39MB | Fastest | Basic | Quick testing |
| base | 74MB | Fast | Good | General use |
| small | 244MB | Medium | Better | Production |
| medium | 769MB | Slow | High | High accuracy |
| large | 1550MB | Slowest | Best | Maximum quality |
OpenAI ASR
ASR:
OpenAIASR:
type: openai
api_key: your_openai_api_key
model_name: whisper-1
language: en
response_format: json
temperature: 0.0
Groq ASR
ASR:
GroqASR:
type: openai
base_url: https://api.groq.com/openai/v1
api_key: your_groq_api_key
model_name: whisper-large-v3
language: en
ASR Configuration
# ASR settings
asr:
provider: WhisperASR
language: null # null for auto-detect
sample_rate: 16000 # Audio sample rate
channels: 1 # Mono audio
chunk_size: 1024 # Audio chunk size
timeout: 30 # Processing timeout
retry_count: 3 # Retry attempts
🧠 Language Processing (LLM)
LLM Providers
OpenAI LLM
LLM:
OpenAILLM:
type: openai
api_key: your_openai_api_key
model_name: gpt-4o-mini
temperature: 0.7
max_tokens: 1000
top_p: 1.0
frequency_penalty: 0.0
presence_penalty: 0.0
Model Options:
- gpt-4o: Latest, most capable
- gpt-4o-mini: Faster, cost-effective
- gpt-3.5-turbo: Budget option
LMStudio LLM
LLM:
LMStudioLLM:
type: openai
base_url: http://localhost:1234/v1
api_key: lm-studio
model_name: llama3.1:8b
temperature: 0.7
max_tokens: 1000
Ollama LLM
LLM:
OllamaLLM:
type: openai
base_url: http://localhost:11434/v1
api_key: ollama
model_name: llama3.1:8b
temperature: 0.7
LLM Configuration
# LLM settings
llm:
provider: OpenAILLM
system_prompt: |
You are Xiaozhi, a helpful AI assistant.
Respond naturally and conversationally.
max_tokens: 1000
temperature: 0.7
top_p: 1.0
timeout: 30
retry_count: 3
🔊 Text-to-Speech (TTS)
TTS Providers
EdgeTTS (Free)
TTS:
EdgeTTS:
type: edge_tts
voice: en-US-AriaNeural
rate: +0%
pitch: +0Hz
volume: +0%
output_format: mp3
Voice Options:
- en-US-AriaNeural: Female, natural
- en-US-GuyNeural: Male, natural
- en-US-JennyNeural: Female, friendly
- en-US-RyanNeural: Male, professional
OpenAI TTS
TTS:
OpenAITTS:
type: openai
api_key: your_openai_api_key
model_name: tts-1
voice: alloy
response_format: mp3
speed: 1.0
Voice Options:
- alloy: Neutral, balanced
- echo: Male, clear
- fable: British accent
- onyx: Deep, authoritative
- nova: Young, energetic
- shimmer: Soft, gentle
Azure TTS
TTS:
AzureTTS:
type: azure
subscription_key: your_azure_key
region: your_azure_region
voice: en-US-AriaNeural
rate: +0%
pitch: +0Hz
TTS Configuration
# TTS settings
tts:
provider: EdgeTTS
voice: en-US-AriaNeural
rate: +0% # Speech rate
pitch: +0Hz # Voice pitch
volume: +0% # Volume level
output_format: mp3 # Audio format
sample_rate: 22050 # Output sample rate
timeout: 30 # Processing timeout
🎯 Wake Word Detection
What is Wake Word Detection?
Wake word detection allows the device to respond only when a specific phrase is spoken, preventing accidental activations and saving power.
Wake Word Configuration
# Wake word settings
wake_word:
enabled: true
phrase: "Hello Xiaozhi"
sensitivity: 0.5 # 0.0 = most sensitive, 1.0 = least sensitive
timeout: 5 # Seconds to listen after wake word
cooldown: 2 # Seconds before listening again
Custom Wake Words
# Multiple wake words
wake_words:
- "Hello Xiaozhi"
- "Hey Assistant"
- "Wake up"
- "Computer"
🔄 Conversation Flow
Basic Conversation
sequenceDiagram
participant U as User
participant E as ESP32
participant S as Server
participant A as ASR
participant L as LLM
participant T as TTS
U->>E: Says "Hello Xiaozhi"
E->>S: Sends audio stream
S->>A: Processes speech
A->>S: Returns text
S->>L: Processes text
L->>S: Returns response
S->>T: Synthesizes speech
T->>S: Returns audio
S->>E: Sends audio
E->>U: Plays response
Conversation States
# Conversation state management
conversation:
states:
idle: "Waiting for wake word"
listening: "Processing speech"
thinking: "Generating response"
speaking: "Playing response"
error: "Handling error"
timeouts:
listening: 10 # Seconds to listen
thinking: 30 # Seconds to generate response
speaking: 60 # Seconds to play response
error: 5 # Seconds to recover
⚙️ Advanced Configuration
Audio Processing
# Audio processing settings
audio:
input:
sample_rate: 16000
channels: 1
bit_depth: 16
buffer_size: 1024
noise_reduction: true
echo_cancellation: true
output:
sample_rate: 22050
channels: 1
bit_depth: 16
buffer_size: 1024
volume: 0.8
equalizer: true
Performance Optimization
# Performance settings
performance:
streaming: true # Enable streaming
parallel_processing: true # Process audio while speaking
cache_responses: true # Cache common responses
preload_models: true # Preload AI models
gpu_acceleration: true # Use GPU when available
Error Handling
# Error handling settings
error_handling:
retry_count: 3
retry_delay: 1
fallback_responses:
- "I didn't catch that, could you repeat?"
- "Sorry, I'm having trouble understanding."
- "Could you speak a bit louder?"
timeout_responses:
- "I'm still thinking..."
- "Let me process that..."
🧪 Testing Voice Interaction
Basic Tests
Wake Word Test
# Test wake word detection
curl -X POST http://localhost:8000/api/test/wake-word \
-H "Content-Type: application/json" \
-d '{"audio_file": "wake_word_test.wav"}'
Speech Recognition Test
# Test speech recognition
curl -X POST http://localhost:8000/api/test/asr \
-H "Content-Type: application/json" \
-d '{"audio_file": "speech_test.wav"}'
Language Processing Test
# Test language processing
curl -X POST http://localhost:8000/api/test/llm \
-H "Content-Type: application/json" \
-d '{"message": "Hello, how are you?"}'
Speech Synthesis Test
# Test speech synthesis
curl -X POST http://localhost:8000/api/test/tts \
-H "Content-Type: application/json" \
-d '{"text": "Hello, this is a test."}'
End-to-End Test
# Complete voice interaction test
curl -X POST http://localhost:8000/api/test/voice-interaction \
-H "Content-Type: application/json" \
-d '{"audio_file": "complete_test.wav"}'
🛠️ Troubleshooting
Common Issues
No Wake Word Detection
- Check microphone connections
- Adjust sensitivity settings
- Test with different wake phrases
- Check audio levels
Poor Speech Recognition
- Improve microphone positioning
- Reduce background noise
- Use appropriate ASR model
- Check audio quality
Slow Response Times
- Enable streaming processing
- Use faster AI models
- Optimize network connection
- Check server performance
Audio Quality Issues
- Check speaker connections
- Adjust volume levels
- Use better audio components
- Optimize audio processing
Performance Optimization
Latency Reduction
# Optimize for low latency
performance:
streaming: true
parallel_processing: true
preload_models: true
gpu_acceleration: true
audio_buffer_size: 512
Accuracy Improvement
# Optimize for accuracy
asr:
model_name: large # Use larger model
language: en # Specify language
temperature: 0.0 # Reduce randomness
llm:
temperature: 0.7 # Balanced creativity
max_tokens: 1000 # Sufficient length
🎯 Best Practices
Voice Interaction Design
- Keep responses concise - Users prefer short, clear responses
- Use natural language - Avoid robotic or formal speech
- Provide feedback - Let users know when you're processing
- Handle errors gracefully - Provide helpful error messages
Performance Optimization
- Use appropriate models - Balance speed and accuracy
- Enable streaming - Process audio while speaking
- Cache responses - Store common responses
- Monitor performance - Track latency and accuracy
User Experience
- Test with real users - Get feedback on voice interaction
- Handle interruptions - Allow users to interrupt responses
- Provide alternatives - Offer text input as backup
- Customize responses - Adapt to user preferences
🎯 Next Steps
After Voice Setup
- Integrations - Connect to other services
- Plugin System - Add custom functionality
- API Reference - Programmatic access
- Advanced Configuration - Fine-tune settings
Advanced Topics
- Custom Wake Words - Create custom wake phrases
- Voice Training - Train for specific users
- Multi-language Support - Support multiple languages
🆘 Need Help?
- Voice Issues? Check Troubleshooting
- Configuration Problems? See Configuration Guide
- Performance Questions? Browse FAQ
🎯 Quick Reference
Voice Providers
- ASR: WhisperASR (local), OpenAIASR (cloud)
- LLM: OpenAILLM (cloud), LMStudioLLM (local)
- TTS: EdgeTTS (free), OpenAITTS (premium)
Key Settings
- Wake Word: "Hello Xiaozhi"
- Language: Auto-detect or specify
- Voice: en-US-AriaNeural
- Sample Rate: 16kHz input, 22kHz output
Testing Commands
# Test wake word
curl -X POST http://localhost:8000/api/test/wake-word
# Test speech recognition
curl -X POST http://localhost:8000/api/test/asr
# Test complete interaction
curl -X POST http://localhost:8000/api/test/voice-interaction
Your voice interaction system is ready! 🎉