Text-to-Speech / TTS
Convert text to audio files with streaming support. Uses the /v1/audio/speech endpoint, compatible with the OpenAI API.
Basic Usage
from pathlib import Path
import openai
client = openai.OpenAI(
api_key="your-api-key",
base_url="https://live-turing.cn.llm.tcljd.com/api/v1",
)
speech_file = Path("hello.mp3")
response = client.audio.speech.create(
model="turing/tts-1",
voice="alloy",
input="Hello, the weather is nice today.",
)
response.stream_to_file(speech_file)
curl $TURING_BASE_URL/audio/speech \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "turing/tts-1",
"voice": "alloy",
"input": "Hello, the weather is nice today."
}' \
--output hello.mp3
Parameters
| Parameter | Description | Values |
|---|---|---|
model | TTS model | See Audio Model List; example uses turing/tts-1 |
voice | Voice | OpenAI: alloy / ash / ballad / coral / echo / sage / shimmer / verse; Qwen: Cherry / Serena, etc. |
input | Text to synthesize | UTF-8 string |
response_format | Output format | mp3 (default) / wav / flac / opus / pcm / aac |
speed | Speech speed | 0.25 – 4.0, default 1.0 |
Full schema: /api/create-speech
Voice Quick Reference
OpenAI voices (more natural emotional expression): alloy, ash, ballad, coral, sage, verse (recommended) / echo, shimmer, alloy (alternatives).
Qwen Omni voices (more natural for Chinese): Cherry, Serena, Ethan, Dylan, etc. (see the Alibaba Cloud DashScope documentation for the full list).
Streaming Response
stream_to_file is a convenience wrapper; the underlying transport is chunked HTTP. To consume the stream directly:
with client.audio.speech.with_streaming_response.create(
model="turing/tts-1",
voice="alloy",
input="...",
) as resp:
with open("out.mp3", "wb") as f:
for chunk in resp.iter_bytes():
f.write(chunk)
Billing
Billed by the number of input characters (see Billing & Usage for per-provider pricing). Speech speed, output format, and voice selection do not affect the unit price.
FAQ
- Qwen voice throws an error with the OpenAI SDK → Set
modelto the Qwen TTS model name; the voice name must also match the model. - Output contains noise → Switch to
response_format: "wav"or use a higher-quality TTS model from the Audio Model List. - Long text is truncated → Synthesize in segments and concatenate; keep a single input under 4096 characters.
- HTTPS stream drops → The client timeout is too short; increase
timeoutor split the input into segments.
See also
/api/create-speech— Full schema + Try-It- Audio Model List — Available TTS models and pricing
- Realtime Voice — Bidirectional voice conversation (alternative to TTS + STT)
- Multimodal Input — Audio as input (GPT-4o audio)