Skip to main content
Generate speech from text using the Voice.ai TTS API.
Prerequisites: API key
1

Get a Voice ID (Optional)

Optionally get a voice_id from your dashboard or clone a voice. Skip this to use the default voice.
2

Generate Speech

Generate speech from text. Include voice_id if you have one, or omit it to use the default voice.
import requests

# Using default voice (voice_id is optional)
response = requests.post(
    'https://dev.voice.ai/api/v1/tts/speech',
    headers={'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json'},
    json={'text': 'Hello! This is a test of the Voice.ai TTS API.'}
)

# Or with a custom voice_id:
# json={'voice_id': 'your-voice-id-here', 'text': 'Hello! This is a test of the Voice.ai TTS API.'}

with open('output.mp3', 'wb') as f:
        f.write(response.content)

Streaming

For real-time streaming, use the streaming endpoint:
import requests

# Using default voice (voice_id is optional)
response = requests.post(
    'https://dev.voice.ai/api/v1/tts/speech/stream',
    headers={'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json'},
    json={'text': 'This text will be streamed in chunks.'},
    stream=True
)

# Or with a custom voice_id:
# json={'voice_id': 'your-voice-id-here', 'text': 'This text will be streamed in chunks.'}

with open('output.mp3', 'wb') as f:
    for chunk in response.iter_content():
        if chunk: f.write(chunk)