Skip to Content

Create speech

Use this interface to generate speech audio from text. The interface format is compatible with the OpenAI audio/speech protocol.

Request Address

MethodURL
POSThttps://api.ant-ling.com/v1/audio/speech

Authorization

Authorization

  • Type: HTTP Bearer Auth, value type string
  • 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

ParameterTypeRequiredDefaultDescription
modelstringYes—TTS model ID
inputstringYes—The text to synthesize into speech
voicestringNo—The voice used to generate speech
referencesobject[]No—Reference audio for voice cloning / voice design
instructionsstringNo—Voice control instructions
response_formatstringNoStream: pcm, Sync: wavThe output audio format
sample_ratenumberNo22050The sample rate of the output audio, in Hz
speednumberNo1.0The speed of the generated speech
volumenumberNo1.0The volume of the generated speech
pitchnumberNo1.0The pitch of the generated speech
stream_formatstringNoDisabledThe 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 null or an empty string.

voice

  • Type: string
  • Optional
  • Description: The voice used to generate speech. Supports system voices. To use a custom voice, set the references parameter 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 example audio/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 pcm for streaming, wav for non-streaming
  • Description: The output audio format.
  • Options: mp3, wav, pcm, opus, aac

sample_rate

  • Type: number
  • Optional, default 22050 Hz
  • 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:
ValueDescription
sseStreams audio as Server-Sent Events; audio data chunks are Base64-encoded and pushed via SSE events
audioStreams 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_formatContent-Type
mp3audio/mpeg
opusaudio/opus
aacaudio/aac
wavaudio/wav
pcmaudio/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 a TTS Event.

speech.audio.delta

  • Type: object
  • Description: An incremental audio chunk event.
data: {"type": "speech.audio.delta", "audio": "//uQxAAAAAANIAAAAAExBTUUzLjEw..."}
  • Fields:
    • type — Fixed value speech.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 value speech.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

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

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>
Was this page helpful?
Last updated on