Overview
This guide will help you set up Coqui TTS (Text-to-Speech) integration with your ADI dashboard. Coqui TTS provides high-quality, offline speech synthesis using advanced neural models like Tacotron2 and HiFiGAN.
01Python Environment Setup
1. Create Python Virtual Environment
First, create a dedicated Python environment for Coqui TTS:
cd ~
mkdir coqui-tts
cd coqui-tts
# Create virtual environment with Python 3.11
pyenv virtualenv 3.11.9 coqui-tts311
pyenv activate coqui-tts311
2. Install Coqui TTS
Install the TTS package and its dependencies:
# Install Coqui TTS (this will take several minutes)
pip install TTS
# For CPU-only systems, install CPU-optimized PyTorch
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
3. Test TTS Installation
Verify the installation works:
tts --text "Hello, ADI is online and speaking through Coqui TTS." \
--model_name tts_models/en/ljspeech/tacotron2-DDC \
--out_path test_output.wav
# Test audio playback (optional)
aplay test_output.wav
02System Integration
4. Create System-Wide TTS Access
Create a symlink so the web server can access TTS:
# Find the TTS binary path
which tts
# Should show: /home/jedi/.pyenv/versions/3.11.9/envs/coqui-tts311/bin/tts
# Create system-wide symlink
sudo ln -s /home/jedi/.pyenv/versions/3.11.9/envs/coqui-tts311/bin/tts /usr/local/bin/tts
# Verify web server can access it
sudo -u www-data which tts
sudo -u www-data tts --help
5. Set Up Directories and Permissions
Create necessary directories with proper permissions:
# Create TTS output and cache directories
sudo mkdir -p /tmp/adi_tts
sudo mkdir -p /tmp/tts_cache
sudo mkdir -p /tmp/tts_config
sudo mkdir -p /tmp/matplotlib_config
# Set ownership and permissions
sudo chown -R www-data:www-data /tmp/adi_tts
sudo chown -R www-data:www-data /tmp/tts_cache
sudo chown -R www-data:www-data /tmp/tts_config
sudo chown -R www-data:www-data /tmp/matplotlib_config
sudo chmod 755 /tmp/adi_tts
sudo chmod 755 /tmp/tts_cache
sudo chmod 755 /tmp/tts_config
sudo chmod 755 /tmp/matplotlib_config
# Create log file
sudo touch /tmp/adi_tts.log
sudo chown www-data:www-data /tmp/adi_tts.log
sudo chmod 666 /tmp/adi_tts.log
03Web Integration
6. Install coqui_tts.php
Create the TTS backend in your web directory:
# Create the PHP file
sudo nano /var/www/html/ai/coqui_tts.php
Copy and paste the complete coqui_tts.php code from the provided template. The key features include:
- Environment variable setup to avoid permission issues
- Text cleaning and preprocessing
- Audio generation with proper error handling
- Base64 encoding for web delivery
- Health check endpoints
7. Update index.php JavaScript
Ensure your dashboard JavaScript calls the correct TTS endpoints:
// Update these lines in your index.php JavaScript:
// For TTS generation:
const response = await fetch('ai/coqui_tts.php', {
// For health checks:
const response = await fetch('ai/coqui_tts.php?health');
04Testing and Verification
8. Test the Health Endpoint
Verify the TTS system is properly configured:
curl http://192.168.1.13/ai/coqui_tts.php?health
"coqui_tts_available": true and other system status information.
9. Test TTS Generation
Test actual speech synthesis:
curl -X POST http://192.168.1.13/ai/coqui_tts.php \
-H "Content-Type: application/json" \
-d '{"text":"Hello test","return_audio":true}'
"success": true and base64 audio data.
10. Test Dashboard Integration
Finally, test the complete integration:
- Open your dashboard:
http://192.168.1.13/ai/index.php - Check that the voice status shows: 🎵 Coqui Ready
- Click "TTS Settings" button
- Click "Test Coqui TTS" - you should hear high-quality speech
- Try sending a regular text message - ADI should speak the response
- Test voice input by clicking the microphone button
Troubleshooting
Common Issues
❌ TTS Error on Dashboard
- Check health endpoint:
http://your-server/ai/coqui_tts.php?health - Verify TTS symlink:
sudo -u www-data which tts - Check directory permissions:
ls -la /tmp/adi_tts/
Permission Denied Errors
# Reset permissions
sudo chown -R www-data:www-data /tmp/adi_tts /tmp/tts_cache /tmp/tts_config
sudo chmod -R 755 /tmp/adi_tts /tmp/tts_cache /tmp/tts_config
Models Not Downloading
- Ensure internet connection is available
- Check that the cache directories are writable
- Monitor
/tmp/adi_tts.logfor detailed error messages
Slow Performance
- First-time model download can take 30-60 seconds
- Subsequent generations should be 2-5 seconds
- Consider using smaller/faster models for production
Log Monitoring
Monitor system logs for issues:
# Check TTS-specific logs
tail -f /tmp/adi_tts.log
# Check Apache error logs
sudo tail -f /var/log/apache2/error.log
# Check PHP errors
sudo tail -f /var/log/php*.log
Configuration Options
Available Models
You can use different TTS models based on your needs:
# List all available models
tts --list_models
# Popular models:
# tts_models/en/ljspeech/tacotron2-DDC (default - good quality)
# tts_models/en/ljspeech/glow-tts (faster)
# tts_models/en/vctk/vits (multi-speaker)
Performance Tuning
Edit /var/www/html/ai/coqui_tts.php to adjust:
$MAX_TEXT_LENGTH- Maximum text length (default: 2000 chars)$MAX_AUDIO_FILES- Audio file cache limit (default: 10)$TTS_MODEL- Default TTS model$VOCODER_MODEL- Default vocoder model
Security Considerations
- The TTS system executes shell commands - ensure input validation
- Limit text length to prevent resource exhaustion
- Monitor disk usage in
/tmp/directories - Consider rate limiting for production deployments
- Regularly clean up temporary audio files