feat: Add Piper TTS integration with pitch control support

- Created PiperTTSService with pitch shifting (-12 to +12 semitones)
- Created UnifiedTTSService to manage multiple TTS engines
- Added engine selection endpoints (GET/POST /api/tts/engines)
- Added voices listing endpoint (GET /api/tts/voices)
- Added pitch_adjustments parameter to TTS generation
- Created install_piper.sh for easy Piper installation
- Updated backend README with multi-engine documentation
- Created comprehensive PIPER_TTS_GUIDE.md
- Added TTS_ENGINE environment variable for engine selection
- Updated requirements.txt with piper-tts and pydub

This allows users to choose between Kokoro (high quality) and Piper
(fast with pitch control) TTS engines at runtime.
This commit is contained in:
2025-12-09 14:45:18 +00:00
parent b5c53604a6
commit bfdcc94b24
8 changed files with 1128 additions and 8 deletions

67
backend/install_piper.sh Executable file
View File

@@ -0,0 +1,67 @@
#!/bin/bash
# Script to install Piper TTS
echo "Installing Piper TTS..."
# Detect OS
OS="$(uname -s)"
ARCH="$(uname -m)"
case "${OS}" in
Linux*)
if [ "${ARCH}" = "x86_64" ]; then
PIPER_URL="https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_amd64.tar.gz"
elif [ "${ARCH}" = "aarch64" ]; then
PIPER_URL="https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_arm64.tar.gz"
else
echo "Unsupported architecture: ${ARCH}"
exit 1
fi
;;
Darwin*)
if [ "${ARCH}" = "x86_64" ] || [ "${ARCH}" = "arm64" ]; then
PIPER_URL="https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_macos_x64.tar.gz"
else
echo "Unsupported architecture: ${ARCH}"
exit 1
fi
;;
*)
echo "Unsupported OS: ${OS}"
exit 1
;;
esac
# Create temp directory
TEMP_DIR=$(mktemp -d)
cd "${TEMP_DIR}"
# Download Piper
echo "Downloading Piper from ${PIPER_URL}..."
curl -L -o piper.tar.gz "${PIPER_URL}"
# Extract
echo "Extracting..."
tar -xzf piper.tar.gz
# Install to /usr/local/bin (requires sudo)
echo "Installing to /usr/local/bin (may require password)..."
sudo cp piper/piper /usr/local/bin/
sudo chmod +x /usr/local/bin/piper
# Cleanup
cd -
rm -rf "${TEMP_DIR}"
# Verify installation
if command -v piper &> /dev/null; then
echo "✓ Piper TTS installed successfully!"
piper --version
else
echo "✗ Installation failed"
exit 1
fi
echo ""
echo "To download voice models, they will be automatically downloaded on first use."
echo "Or you can manually download from: https://github.com/rhasspy/piper/releases/tag/v1.2.0"