xiaozhi-esp32-server/docs/configuration/providers.md
lapy ed8c012588 docs: English-first documentation, images, and licensing
- 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
2026-04-25 17:05:22 +01:00

10 KiB

🤖 AI Providers Configuration

Configure your AI providers to enable speech recognition, language processing, and text-to-speech capabilities. Xiaozhi supports multiple providers for flexibility and cost optimization.

🎯 Provider Overview

AI Stack Components

graph TB
    A[ESP32 Device] --> B[Speech Recognition]
    B --> C[Language Processing]
    C --> D[Response Generation]
    D --> E[Text-to-Speech]
    E --> A
    
    F[ASR Providers] --> B
    G[LLM Providers] --> C
    H[TTS Providers] --> E

Provider Categories

Category Purpose Examples
ASR Speech-to-Text Whisper, OpenAI, Groq
LLM Language Processing OpenAI, LMStudio, Ollama
TTS Text-to-Speech EdgeTTS, OpenAI, Azure
VLLM Vision Processing OpenAI, Local Models

🆓 Free Tier Setup

# Free AI Stack
selected_module:
  ASR: WhisperASR          # Local speech recognition
  LLM: LMStudioLLM         # Local language model
  TTS: EdgeTTS             # Free text-to-speech
  VLLM: OpenAILLMVLLM      # OpenAI vision (optional)

WhisperASR (Speech Recognition)

ASR:
  WhisperASR:
    type: whisper
    model_name: base        # Options: tiny, base, small, medium, large
    device: auto           # auto, cpu, cuda
    language: null         # null for auto-detect, or "en", "es", etc.
    output_dir: tmp/

Model Sizes:

  • tiny: ~39MB - Fastest, lowest accuracy
  • base: ~74MB - Good balance
  • small: ~244MB - Better accuracy
  • medium: ~769MB - High accuracy
  • large: ~1550MB - Best accuracy

LMStudioLLM (Language Model)

LLM:
  LMStudioLLM:
    type: openai
    base_url: http://localhost:1234/v1
    api_key: lm-studio
    model_name: llama3.1:8b

Setup Steps:

  1. Download LMStudio: lmstudio.ai
  2. Load a model: Download llama3.1:8b or similar
  3. Start local server: Enable local API
  4. Configure Xiaozhi: Use local API endpoint

EdgeTTS (Text-to-Speech)

TTS:
  EdgeTTS:
    type: edge_tts
    voice: en-US-AriaNeural    # Voice options
    rate: +0%                  # Speech rate
    pitch: +0Hz                # Voice pitch
    volume: +0%                # Volume level

Voice Options:

  • en-US-AriaNeural: Female, natural
  • en-US-GuyNeural: Male, natural
  • en-US-JennyNeural: Female, friendly
  • en-US-RyanNeural: Male, professional

💎 Premium Setup

OpenAI Configuration

# Premium AI Stack
selected_module:
  ASR: OpenAIASR
  LLM: OpenAILLM
  TTS: OpenAITTS
  VLLM: OpenAILLMVLLM

OpenAI ASR

ASR:
  OpenAIASR:
    type: openai
    api_key: your_openai_api_key
    model_name: whisper-1
    language: en
    response_format: json

OpenAI LLM

LLM:
  OpenAILLM:
    type: openai
    api_key: your_openai_api_key
    model_name: gpt-4o-mini        # Options: gpt-4o, gpt-4o-mini, gpt-3.5-turbo
    temperature: 0.7
    max_tokens: 1000
    top_p: 1.0

Model Options:

  • gpt-4o: Latest, most capable
  • gpt-4o-mini: Faster, cost-effective
  • gpt-3.5-turbo: Budget option

OpenAI TTS

TTS:
  OpenAITTS:
    type: openai
    api_key: your_openai_api_key
    model_name: tts-1              # Options: tts-1, tts-1-hd
    voice: alloy                   # Options: alloy, echo, fable, onyx, nova, shimmer
    response_format: mp3
    speed: 1.0

🔧 Advanced Configurations

Hybrid Setup (Best of Both Worlds)

# Hybrid Configuration
selected_module:
  ASR: WhisperASR          # Local for privacy
  LLM: OpenAILLM           # Cloud for capability
  TTS: EdgeTTS             # Free for cost

Privacy-Focused Setup

# Complete Local Setup
selected_module:
  ASR: WhisperASR          # Local processing
  LLM: LMStudioLLM         # Local processing
  TTS: EdgeTTS             # Local processing

Performance-Optimized Setup

# High-Performance Configuration
selected_module:
  ASR: OpenAIASR           # Cloud for speed
  LLM: OpenAILLM          # Cloud for capability
  TTS: OpenAITTS          # Cloud for quality

🌐 Additional Providers

Groq (Fast LLM)

LLM:
  GroqLLM:
    type: openai
    base_url: https://api.groq.com/openai/v1
    api_key: your_groq_api_key
    model_name: llama-3.1-70b-versatile

Ollama (Local LLM)

LLM:
  OllamaLLM:
    type: openai
    base_url: http://localhost:11434/v1
    api_key: ollama
    model_name: llama3.1:8b

Azure Cognitive Services

ASR:
  AzureASR:
    type: azure
    subscription_key: your_azure_key
    region: your_azure_region
    language: en-US

TTS:
  AzureTTS:
    type: azure
    subscription_key: your_azure_key
    region: your_azure_region
    voice: en-US-AriaNeural

⚙️ Configuration Methods

Method 1: Web Interface

  1. Open web interface: http://localhost:8001
  2. Go to Model Configuration
  3. Select provider type (ASR, LLM, TTS)
  4. Configure settings and API keys
  5. Save configuration

Method 2: Configuration File

# Edit configuration file
nano data/.config.yaml

# Add provider configuration
ASR:
  WhisperASR:
    type: whisper
    model_name: base

LLM:
  OpenAILLM:
    type: openai
    api_key: your_api_key
    model_name: gpt-4o-mini

TTS:
  EdgeTTS:
    type: edge_tts
    voice: en-US-AriaNeural

Method 3: Environment Variables

# Set environment variables
export OPENAI_API_KEY=your_api_key
export GROQ_API_KEY=your_groq_key
export AZURE_SUBSCRIPTION_KEY=your_azure_key

# Restart server
docker-compose restart

🧪 Testing Providers

Test Speech Recognition

# Test ASR provider
curl -X POST http://localhost:8000/api/test/asr \
  -H "Content-Type: application/json" \
  -d '{"audio_file": "test.wav"}'

Test Language Model

# Test LLM provider
curl -X POST http://localhost:8000/api/test/llm \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello, how are you?"}'

Test Text-to-Speech

# Test TTS provider
curl -X POST http://localhost:8000/api/test/tts \
  -H "Content-Type: application/json" \
  -d '{"text": "Hello, this is a test."}'

💰 Cost Optimization

Free Tier Strategy

# Maximize free usage
selected_module:
  ASR: WhisperASR          # Completely free
  LLM: LMStudioLLM         # Completely free
  TTS: EdgeTTS             # Completely free

Hybrid Cost Strategy

# Balance cost and quality
selected_module:
  ASR: WhisperASR          # Free for privacy
  LLM: OpenAILLM           # Pay for capability
  TTS: EdgeTTS             # Free for cost

Usage Monitoring

# Monitor API usage
curl -X GET http://localhost:8000/api/usage/stats

# Check provider status
curl -X GET http://localhost:8000/api/providers/status

🛠️ Troubleshooting

Common Issues

API Key Errors

# Check API key format
echo $OPENAI_API_KEY

# Test API key
curl -H "Authorization: Bearer $OPENAI_API_KEY" \
  https://api.openai.com/v1/models

Provider Connection Issues

# Check provider status
curl -X GET http://localhost:8000/api/providers/health

# View provider logs
docker-compose logs xiaozhi-server | grep -i provider

Model Loading Issues

# Check model files
ls -la models/whisper/
ls -la models/vosk/

# Verify model integrity
python -c "import whisper; whisper.load_model('base')"

Performance Optimization

Local Model Optimization

# Optimize Whisper performance
ASR:
  WhisperASR:
    device: cuda           # Use GPU if available
    model_name: base       # Balance speed/accuracy
    language: en           # Specify language for speed

Cloud Provider Optimization

# Optimize OpenAI usage
LLM:
  OpenAILLM:
    model_name: gpt-4o-mini    # Use faster model
    max_tokens: 500            # Limit response length
    temperature: 0.7           # Reduce randomness

🎯 Best Practices

Provider Selection

  1. Start with free providers for testing
  2. Use local providers for privacy-sensitive applications
  3. Use cloud providers for production and high-volume usage
  4. Mix providers for optimal cost/performance balance

Configuration Management

  1. Use environment variables for sensitive data
  2. Version control configuration files
  3. Test configurations before deploying
  4. Monitor usage and costs regularly

Security Considerations

  1. Rotate API keys regularly
  2. Use least privilege access
  3. Monitor API usage for anomalies
  4. Encrypt sensitive data at rest

🎯 Next Steps

After Configuration

  1. Basic Setup - Configure server settings
  2. Test Voice Interaction - Verify everything works
  3. Connect ESP32 Device - Add your first device
  4. Advanced Configuration - Fine-tune your setup

Advanced Topics

🆘 Need Help?


🎯 Quick Reference

Free Providers

  • ASR: WhisperASR (local)
  • LLM: LMStudioLLM (local)
  • TTS: EdgeTTS (free)

Premium Providers

  • ASR: OpenAIASR
  • LLM: OpenAILLM
  • TTS: OpenAITTS

Configuration Files


Your AI providers are now configured! 🎉

👉 Next: Basic Setup →