PlayHT
Text-to-speech services using PlayHT’s WebSocket and HTTP APIs
Overview
PlayHT provides two TTS service implementations:
PlayHTTTSService
: WebSocket-based service with real-time streamingPlayHTHttpTTSService
: HTTP-based service for simpler, non-streaming synthesis
Installation
To use PlayHT services, install the required dependencies:
You’ll also need to set up your PlayHT credentials as environment variables:
PLAY_HT_USER_ID
PLAY_HT_API_KEY
PlayHTTTSService
WebSocket-based implementation supporting real-time streaming synthesis.
Constructor Parameters
PlayHT API key
PlayHT user ID
Voice identifier URL
TTS engine identifier. See the PlayHT docs for available engines.
Output audio sample rate in Hz
Audio output format
Modifies text provided to the TTS. Learn more about the available filters.
Input Parameters
PlayHTHttpTTSService
HTTP-based implementation for simpler synthesis requirements.
Constructor Parameters
PlayHT API key
PlayHT user ID
Voice identifier URL
TTS engine identifier. See the PlayHT docs for available engines.
Output audio sample rate in Hz
Input Parameters
Output Frames
Control Frames
Signals start of synthesis
Signals completion of synthesis
Audio Frames
Contains generated audio data with: - WAV format - Specified sample rate - Single channel (mono)
Error Frames
Contains PlayHT error information
Methods
See the TTS base class methods for additional functionality.
Language Support
Supports multiple languages when using the PlayHT3.0-mini
engine:
Language Code | Description | Service Code |
---|---|---|
Language.BG | Bulgarian | BULGARIAN |
Language.CA | Catalan | CATALAN |
Language.CS | Czech | CZECH |
Language.DA | Danish | DANISH |
Language.DE | German | GERMAN |
Language.EN | English | ENGLISH |
Language.ES | Spanish | SPANISH |
Language.FR | French | FRENCH |
Language.EL | Greek | GREEK |
Language.HI | Hindi | HINDI |
Language.HU | Hungarian | HUNGARIAN |
Language.ID | Indonesian | INDONESIAN |
Language.IT | Italian | ITALIAN |
Language.JA | Japanese | JAPANESE |
Language.KO | Korean | KOREAN |
Language.MS | Malay | MALAY |
Language.NL | Dutch | DUTCH |
Language.PL | Polish | POLISH |
Language.PT | Portuguese | PORTUGUESE |
Language.RU | Russian | RUSSIAN |
Language.SV | Swedish | SWEDISH |
Language.TH | Thai | THAI |
Language.TR | Turkish | TURKISH |
Language.UK | Ukrainian | UKRAINIAN |
Usage Examples
WebSocket Service
HTTP Service
Frame Flow
WebSocket Service
HTTP Service
Metrics Support
Both services collect processing metrics:
- Time to First Byte (TTFB)
- Processing duration
- Character usage
- API calls
Notes
WebSocket Service
- Real-time streaming support
- Automatic reconnection
- Interruption handling
- WAV header management
- Thread-safe processing
HTTP Service
- Simpler implementation
- Complete audio delivery
- WAV header parsing
- Chunked audio delivery
- Lower latency for short texts
Common Features
- Multiple voice engines
- Speed control
- Language support
- Seed-based consistency
- Error handling
- Metrics collection