Create speech
Use this interface to generate speech audio from text. The interface format is compatible with the OpenAI audio/speech protocol.
Request Address
| Method | URL |
|---|---|
POST | https://api.ant-ling.com/v1/audio/speech |
Authorization
Authorization
- Type:
HTTP Bearer Auth, value typestring - Required
- Description: Used to verify account information. Go to API Console , click Create Token to obtain.
Authorization: Bearer <YOUR_API_KEY>Request Headers
Content-Type
- Type:
enum<string> - Required, fixed value
application/json - Description: The media type of the request body. Must be
application/json.
Request Body
Overview
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | — | TTS model ID |
input | string | Yes | — | The text to synthesize into speech |
voice | string | No | — | The voice used to generate speech |
references | object[] | No | — | Reference audio for voice cloning / voice design |
instructions | string | No | — | Voice control instructions |
response_format | string | No | Stream: pcm, Sync: wav | The output audio format |
sample_rate | number | No | 22050 | The sample rate of the output audio, in Hz |
speed | number | No | 1.0 | The speed of the generated speech |
volume | number | No | 1.0 | The volume of the generated speech |
pitch | number | No | 1.0 | The pitch of the generated speech |
stream_format | string | No | Disabled | The streaming return mode of the audio data |
model
- Type:
string - Required
- Description: The ID of the TTS model to use.
- Options:
Ming-3.0-tts
input
- Type:
string - Required
- Description: The text content to synthesize into speech. Maximum length is 2048 characters. Must not be
nullor an empty string.
voice
- Type:
string - Optional
- Description: The voice used to generate speech. Supports system voices. To use a custom voice, set the
referencesparameter instead.
references
- Type:
object[] - Optional
- Description: A list of reference audio clips used for stateless voice cloning or voice design, which serves as the custom voice for the generated speech. The current model supports at most 1 reference, each up to 30 seconds and no larger than 10 MB, in WAV format.
references[].audio
- Type:
string - Required
- Description: The Base64-encoded audio data of the reference sample. For best results, use 10–30 seconds of clear speech with as little background noise as possible. Supported format: WAV.
Convert the audio file to a Base64-encoded string before passing it in. The encoded string must not exceed 10 MB. Prefix the Base64 string with data:{MIME_TYPE};base64,$BASE64_AUDIO:
{MIME_TYPE}— the MIME type of the audio file, used to identify its format. Replace it with the actual MIME value, for exampleaudio/wav.$BASE64_AUDIO— the pure Base64-encoded string of the audio file (without any prefix).
references[].text
- Type:
string - Required
- Description: The verbatim transcript of what is said in the audio sample. The accuracy of both the audio and this transcript is critical to voice cloning quality.
instructions
- Type:
string - Optional
- Description: Voice control instructions for the generated speech. Use a voice style description so the speech is narrated with the designed voice.
response_format
- Type:
string - Optional, default
pcmfor streaming,wavfor non-streaming - Description: The output audio format.
- Options:
mp3,wav,pcm,opus,aac
sample_rate
- Type:
number - Optional, default
22050Hz - Description: The sample rate of the output audio, in Hz.
- Options:
8000,16000,22050,24000
speed
- Type:
number - Optional, default
1.0 - Description: The speed of the generated speech. Range
[0.25, 4.0].
volume
- Type:
number - Optional, default
1.0 - Description: The volume of the generated speech. Range
[0.5, 2.0].
pitch
- Type:
number - Optional, default
1.0 - Description: The pitch of the generated speech. Range
[0.5, 2.0].
stream_format
- Type:
string - Optional
- Description: Enables streaming audio return, suitable for low-latency scenarios that play audio while it is being generated.
- Options:
| Value | Description |
|---|---|
sse | Streams audio as Server-Sent Events; audio data chunks are Base64-encoded and pushed via SSE events |
audio | Streams raw audio binary data directly via chunked transfer encoding |
Ming-3.0-tts currently only supports sse, not audio.
The sse mode suits browser clients consuming audio via EventSource, with clear event boundaries and an end signal; the audio mode suits server-side or native clients consuming the audio stream directly, with lower overhead.
Response Body
Non-Streaming
The response is of type file — audio bytes. The Content-Type of the HTTP response varies with the response_format parameter:
| response_format | Content-Type |
|---|---|
mp3 | audio/mpeg |
opus | audio/opus |
aac | audio/aac |
wav | audio/wav |
pcm | audio/pcm |
SSE Stream
- Content-Type:
text/event-stream - Description: Server-Sent Events stream. Each frame is
data: <json>\n\n, where the JSON payload matches aTTS Event.
speech.audio.delta
- Type:
object - Description: An incremental audio chunk event.
data: {"type": "speech.audio.delta", "audio": "//uQxAAAAAANIAAAAAExBTUUzLjEw..."}- Fields:
type— Fixed valuespeech.audio.delta.audio— A chunk of Base64-encoded audio data.
speech.audio.done
- Type:
object - Description: The terminating event indicating that speech synthesis is complete.
data: {"type": "speech.audio.done", "usage": {"prompt_tokens": 12, "completion_tokens": 80, "total_tokens": 92}}- Fields:
type— Fixed valuespeech.audio.done.usage— Token usage statistics:prompt_tokens(input),completion_tokens(output),total_tokens(total).
Audio Byte Stream
- Content-Type: Corresponds to
response_format(see the table above) - Description: The response is a raw audio bytestream streamed via HTTP chunked transfer encoding.
Example
Request Example
System Voice
cURL
curl --request POST \
--url https://api.ant-ling.com/v1/audio/speech \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"model": "Ming-3.0-tts",
"input": "Hello, who are you?",
"voice": "UK_Charlotte",
"response_format": "pcm",
"stream_format": "sse"
}'Response Example
Non-Streaming Response
When stream_format is not set, streaming is disabled and the response is the binary content of the audio file in the corresponding format.
HTTP/1.1 200 OK
Content-Type: audio/wav
<binary audio data>