Overview
Tabbly TTS provides a streaming Text-to-Speech API that allows you to use Tabbly TTS as a TTS provider in your LiveKit voice agents with optimized audio delivery that eliminates clicks, pops, and choppy sounds.Prerequisites
- LiveKit Agents Python SDK installed
- Tabbly TTS API key
- Python 3.11+
httpxlibrary (for HTTP streaming)
API Details
Base URL:https://api.tabbly.io
Streaming Endpoint: POST /tts/stream
Authentication: API key via X-API-Key header
Response Format: HTTP streaming response with WAV-encoded audio chunks (LINEAR16, 48kHz, mono)
Protocol: HTTP streaming with WAV files embedded in the stream
Integration Steps
1. Create the TTS Class
Create a custom TTS class that inherits fromlivekit.agents.tts.TTS:
2. Create the ChunkedStream Class
Implement aChunkedStream that handles the audio streaming with optimized buffering:
3. Use in Your Agent
In your LiveKit agent entrypoint:Configuration Options
TabblyTTS Parameters
string
required
Your Tabbly TTS API key
string
default:"Ashley"
Voice ID to use (default: “Ashley”)
string
default:"tabbly-tts"
Model ID to use (default: “tabbly-tts”)
string
default:"https://api.tabbly.io"
Base URL for the API
Audio Configuration
integer
48000 Hz (fixed)
integer
1 (mono)
string
LINEAR16 PCM (16-bit)
string
audio/pcm
Buffering Strategy
The implementation uses an optimized buffering strategy to eliminate audio artifacts:- Chunk Size: 960 bytes (10ms at 48kHz) - reduces overhead and prevents clicks
- Pre-buffer Size: 1920 bytes (20ms) - smooths out network jitter
- Frame Alignment: All chunks are aligned to 16-bit sample boundaries (even number of bytes)
Key Features
1. WAV File Extraction
The API may send WAV files embedded in the stream. The implementation automatically:- Detects WAV headers (
RIFFandWAVEmarkers) - Extracts raw PCM data from WAV chunks
- Handles multiple WAV files in a single stream
- Falls back to raw PCM if no WAV headers are detected
2. Optimized Audio Delivery
The implementation eliminates audio clicks, pops, and choppy sounds by:- Using consistent 10ms chunk sizes for steady delivery
- Pre-buffering 20ms to smooth network jitter
- Ensuring perfect frame alignment (16-bit sample boundaries)
- Processing data continuously without gaps
3. Error Handling
The implementation handles:- HTTP errors from the API
- WAV header parsing errors
- Network timeouts (60 seconds)
- AudioEmitter initialization errors
- Incomplete WAV files in the stream
Best Practices
HTTP Streaming
HTTP Streaming
Uses HTTP streaming for better reliability than WebSocket
Error Handling
Error Handling
Always wrap TTS calls in try-except blocks to handle network and API errors gracefully
Monitor API Usage
Monitor API Usage
Track your API usage through Tabbly’s dashboard to manage costs and quotas
Voice Selection
Voice Selection
Choose appropriate voice_id based on your use case. Different voices may have different characteristics and languages
Model Selection
Model Selection
Use the appropriate model_id (default: “tabbly-tts”)
WAV Processing
WAV Processing
The implementation automatically handles WAV files - no manual processing needed
Buffering
Buffering
The pre-buffer helps smooth out network delays - don’t disable it
Frame Alignment
Frame Alignment
Always ensure sample-aligned chunks to prevent audio artifacts
Example: Using with Metadata
You can configure Tabbly TTS via LiveKit job metadata:Troubleshooting
No Audio Output
- Check API key is valid and has wallet balance > 0
- Verify network connectivity to API endpoint (
https://api.tabbly.io) - Check logs for HTTP connection errors
- Verify the response status code is 200
- Check if WAV headers are being detected correctly
Audio Quality Issues (Clicks, Pops, Choppy Sound)
This is the main issue this implementation solves!- Ensure the pre-buffer is working (check logs for buffer sizes)
- Verify chunk size is 960 bytes (10ms)
- Check that frame alignment is correct (even number of bytes)
- Monitor network latency - high latency may require larger pre-buffer
- Ensure WAV extraction is working (check debug logs)
HTTP Connection Issues
- Check firewall/proxy settings for HTTPS connections
- Verify API URL is correct (
https://api.tabbly.io/tts/stream) - Check for HTTP timeout errors (default 60 seconds)
- Ensure API key is properly included in
X-API-Keyheader - Verify request format matches API requirements
Performance Issues
- Monitor HTTP connection establishment time
- Check for network latency to API endpoint
- Monitor audio chunk arrival rate
- Check if pre-buffer is filling up (may indicate slow network)
- Consider adjusting CHUNK_SIZE or PRE_BUFFER_SIZE for your network conditions
WAV Processing Issues
- Check logs for “Extracted PCM from WAV” messages
- Verify WAV headers are being detected (
RIFFandWAVEmarkers) - Check if multiple WAV files are being processed correctly
- Ensure incomplete WAV files are being handled (kept in buffer)
Audio Artifact Prevention
This implementation specifically addresses audio artifacts (clicks, pops, choppy sounds) through:- Consistent Chunk Sizes: 10ms chunks provide steady delivery rate
- Pre-buffering: 20ms buffer smooths out network jitter
- Frame Alignment: All chunks aligned to 16-bit sample boundaries
- Continuous Processing: No gaps between chunks
- WAV Extraction: Properly extracts PCM from embedded WAV files
- Increase PRE_BUFFER_SIZE (try 2880 bytes = 30ms)
- Check network latency and stability
- Verify the API is sending consistent data
- Check for any errors in the logs
Support
For issues or questions:- Check TTS Streaming API documentation
- Review LiveKit Agents documentation
- Check application logs for detailed error messages
- Verify your implementation matches the code provided above