fix: Update Piper TTS to support voice preview and improve setup

- Fixed preview endpoint to work with both Kokoro and Piper engines
- Improved voice model download with curl fallback and SSL handling
- Added better error messages when models are missing
- Created PIPER_SETUP.md with manual download instructions
- Added test_piper_direct.py for testing Piper installation
- Updated README with voice model download requirements

Note: Piper voice models require manual download from GitHub releases
due to HuggingFace URL structure. See PIPER_SETUP.md for instructions.
This commit is contained in:
2025-12-09 14:56:48 +00:00
parent 6f7330c491
commit d3e72edd7f
6 changed files with 300 additions and 26 deletions

98
backend/PIPER_SETUP.md Normal file
View File

@@ -0,0 +1,98 @@
# Piper TTS Setup Guide
## Quick Start
Piper TTS is now integrated but requires manual voice model setup.
### 1. Install Piper
```bash
cd backend
./install_piper.sh
```
Verify installation:
```bash
piper --version
```
### 2. Download Voice Models
Piper voice models need to be downloaded manually and placed in `backend/piper_models/`.
**Download voices from:**
https://github.com/rhasspy/piper/releases/tag/v1.2.0
**Recommended voices for English:**
1. **en_US-lessac-medium** (Male, American)
- Download: `en_US-lessac-medium.onnx` and `en_US-lessac-medium.onnx.json`
- Place in: `backend/piper_models/`
2. **en_US-amy-medium** (Female, American)
- Download: `en_US-amy-medium.onnx` and `en_US-amy-medium.onnx.json`
- Place in: `backend/piper_models/`
3. **en_GB-alan-medium** (Male, British)
- Download: `en_GB-alan-medium.onnx` and `en_GB-alan-medium.onnx.json`
- Place in: `backend/piper_models/`
### 3. Directory Structure
After downloading, your directory should look like:
```
backend/
├── piper_models/
│ ├── en_US-lessac-medium.onnx
│ ├── en_US-lessac-medium.onnx.json
│ ├── en_US-amy-medium.onnx
│ ├── en_US-amy-medium.onnx.json
│ ├── en_GB-alan-medium.onnx
│ └── en_GB-alan-medium.onnx.json
└── ...
```
### 4. Test Piper
```bash
cd backend
python test_piper_direct.py
```
### 5. Use in Application
1. Start the backend server
2. In the frontend, click "Piper TTS" button in Voice Assignment screen
3. Select Piper voices from the dropdown
4. Generate audiobook with pitch control!
## Troubleshooting
### "Model not found" error
- Make sure you downloaded both `.onnx` and `.onnx.json` files
- Check files are in `backend/piper_models/` directory
- Verify filenames match exactly (case-sensitive)
### "Piper not found" error
- Run `./install_piper.sh` to install Piper
- Or install manually from https://github.com/rhasspy/piper/releases
### Synthesis fails
- Check Piper version: `piper --version`
- Try running Piper directly: `echo "test" | piper --model piper_models/en_US-lessac-medium.onnx --output-raw > test.wav`
- Check backend logs for detailed error messages
## Alternative: Use Kokoro TTS
If Piper setup is too complex, you can continue using Kokoro TTS (the default engine) which works out of the box with no additional setup.
## More Voices
Browse all available Piper voices:
https://rhasspy.github.io/piper-samples/
Download any voice and place the `.onnx` and `.onnx.json` files in `backend/piper_models/`.