Converts text to speech using ByteDance Volcano Engine TTS V3 HTTP streaming API.
Prerequisites
Set environment variables:
export DOUBAO_APPID="your-appid"
export DOUBAO_TOKEN="your-access-token"
Install dependencies:
pip install requests
Quick Start
python {baseDir}/scripts/tts.py --text "Hello, this is a test." --output output.mp3
Parameters
| Parameter | Required | Default | Description |
|---|---|---|---|
--text |
Yes | - | Text to synthesize (max 1024 bytes, recommended <300 chars) |
--voice_type |
No | zh_female_cancan_mars_bigtts |
Voice ID |
--encoding |
No | mp3 |
Output format: mp3, wav, pcm, ogg_opus |
--output |
No | output.<encoding> |
Output file path |
--speed_ratio |
No | 1.0 |
Speed ratio (0.1 - 2.0) |
--emotion |
No | - | Emotion for multi-emotion voices |
Usage Examples
Basic synthesis:
python {baseDir}/scripts/tts.py --text "Welcome to Doubao TTS service."
Custom voice and format:
python {baseDir}/scripts/tts.py \
--text "This is synthesized with a different voice." \
--voice_type zh_male_rap_mars_bigtts \
--encoding wav \
--output custom_voice.wav
Adjust speed:
python {baseDir}/scripts/tts.py \
--text "This is slower speech." \
--speed_ratio 0.8 \
--output slow.mp3
With emotion (for supported voices):
python {baseDir}/scripts/tts.py \
--text "I am very happy today!" \
--voice_type zh_female_shuangkuaisisi_moon_bigtts \
--emotion happy \
--output happy.mp3
Voice Types
For a complete list of available voices, see VOICES.md.
Common voice types:
zh_female_cancan_mars_bigtts- Female, Cancan (default)zh_male_rap_mars_bigtts- Male, Rap stylezh_female_shuangkuaisisi_moon_bigtts- Female, supports emotions
Error Handling
| Code | Description | Solution |
|---|---|---|
| 3000 | Success | - |
| 3001 | Invalid request | Check parameters |
| 3003 | Concurrent limit exceeded | Retry later |
| 3010 | Text too long | Split into smaller chunks (<300 chars) |
| 3011 | Invalid text | Check text content |
| 3050 | Voice not found | Verify voice_type parameter |
API Reference
- Endpoint:
https://openspeech.bytedance.com/api/v3/tts/unidirectional - Method: HTTP POST with streaming response
- Authentication:
Authorization: Bearer; {token}