API Platform

Streaming Speech

Use TTS 1.5 Flash for low-latency streaming speech generation. This capability uses the same endpoint as single-speaker speech and is enabled with version=flash-20260626 and stream=true.

POST
/v1/audio/speech

The request body is JSON. stream_format=sse returns SSE; omitting stream_format or passing audio returns raw PCM bytes.

Authentication

Add Authorization: Bearer <API_KEY> to the request headers to authenticate. You can generate a key on the console "API Keys" page.

Example
curl https://api.mosi.cn/v1/audio/speech \
  -H "Authorization: Bearer $MOSS_API_KEY"

Supported models

FieldAllowed values
model

moss-tts

version

flash-20260626

Activation requirements and constraints

  • Pass the exact lowercase value model=moss-tts; letter case is not normalized.
  • version is required and must be flash-20260626.
  • stream is required and must be true.
  • response_format is required; currently only pcm is supported.
  • stream_format=sse returns SSE, with each frame formatted as data: JSON Event.
  • Omitting stream_format or passing audio returns raw PCM bytes.
  • sample_rate is not a public request field; passing a non-zero value returns a parameter error before task creation.
  • stream=true cannot be combined with async=true, and streaming calls do not accept a non-empty webhook_url.
  • voice_url, voice_data, and file_id are not supported for streaming calls; use voice_id to specify a voice ID.
  • delivery_method and aigc_metadata currently have no effect on the streaming path; do not pass them.

Request fields

FieldTypeRequiredDescription
modelstringYes

Must be the exact lowercase value moss-tts.

versionstringYes

Must be flash-20260626; without this version, TTS 1.5 Flash streaming speech generation is not enabled.

inputstringYes

The text to synthesize.

voice_idstringNo

Voice ID; get one via List Voices, or go to the Mossland voice library and copy it from a voice card's copy icon. TTS accepts only a voice ID and does not support voice_url / voice_data, nor inline or reference audio.

languagestringNo

Language hint, trimmed before it is passed to the model.

speednumberNo

Speech speed. The default is 1, and the allowed range is 0.25-4; values outside this range return a parameter error.

expected_duration_secnumberNo

Expected audio duration in seconds. When provided, it must be greater than 0.

streambooleanYes

Set to true to enable TTS 1.5 Flash streaming speech generation.

response_formatstringYes

Streaming requests currently support only pcm.

stream_formatstringNo

audio or sse. The default is audio, which returns raw PCM bytes; sse returns data: JSON Events.

Request examples

curl --no-buffer -X POST "https://api.mosi.cn/v1/audio/speech" \
  -H "Authorization: Bearer $MOSS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "moss-tts",
    "version": "flash-20260626",
    "input": "Welcome to the Mossland API.",
    "voice_id": "<voice_id>",
    "language": "en",
    "speed": 1,
    "expected_duration_sec": 3,
    "stream": true,
    "response_format": "pcm",
    "stream_format": "sse"
  }'

Streaming response

stream_format=sse returns SSE, with each data: line followed by a JSON Event. type is the event discriminator; clients should use it to select the corresponding field structure. Omitting stream_format or passing audio returns raw PCM bytes.

Some access paths return task.created first, while others start directly with speech.created. Clients must use each frame's type and must not depend on a fixed first event.

SSE Event Types

Event TypeDescriptionTerminal
task.createdMay be returned after the streaming task is created; not all access paths send itNo
speech.createdDeclares the format parameters for subsequent PCM audio chunksNo
speech.audio.deltaA Base64-encoded PCM audio chunk; zero or more may be returnedNo
speech.audio.doneTerminal event for a successful TTS stream; clients may stop reading after receiving itYes
errorReturned when a failure occurs after the stream starts; stop reading after receiving itYes

task.created

FieldTypeAlways returnedDescription
typestringYes

Always task.created.

task_idstringYes

The streaming task ID created by AGW.

objectstringYes

Always audio.speech.

statusstringYes

Usually PROCESSING at creation time.

modelstringYes

The public model name used by the client request.

speech.created

FieldTypeAlways returnedDescription
typestringYes

Always speech.created.

formatstringYes

Currently must be pcm; other values cause the stream to fail.

sample_rateintegerYes

Sample rate in Hz. It must be positive and within the WAV parameter range; follow the downstream event value.

channelsintegerYes

Channel count. It must be positive and within the WAV parameter range; follow the downstream event value.

bit_depthintegerYes

Bit depth. It must be positive, divisible by 8, and within the WAV parameter range; follow the downstream event value.

speech.audio.delta

FieldTypeAlways returnedDescription
typestringYes

Always speech.audio.delta.

audiostringNormally

When non-empty, a Base64-encoded PCM byte chunk. The current implementation allows an empty string; clients should ignore empty chunks.

speech.audio.done

FieldTypeAlways returnedDescription
typestringYes

Always speech.audio.done.

error

FieldTypeAlways returnedDescription
typestringYes

Always error.

errorobjectNormally

Error details.

error.codestringNo

Machine-readable error code.

error.messagestringNo

Error description.

Raw PCM response headers

FieldTypePresenceDescription
Content-TypeHTTP headerAlwaysAlways audio/pcm.
X-Sample-RateHTTP headerAlwaysRaw PCM sample rate; clients must use this value to interpret the audio.
X-ChannelsHTTP headerAlwaysRaw PCM channel count.
X-Bit-DepthHTTP headerAlwaysRaw PCM bit depth.

Response example

SSE and raw PCM
# SSE response example: pass stream_format=sse in the request
Content-Type: text/event-stream; charset=utf-8

# Some access paths omit task.created and start directly with speech.created
data: {"type":"task.created","task_id":"task-123","object":"audio.speech","status":"PROCESSING","model":"moss-tts"}

data: {"type":"speech.created","format":"pcm","sample_rate":48000,"channels":1,"bit_depth":16}

data: {"type":"speech.audio.delta","audio":"BASE64_PCM_CHUNK"}

data: {"type":"speech.audio.done"}

# Raw PCM response example: omit stream_format or pass stream_format=audio
Content-Type: audio/pcm
X-Sample-Rate: 48000
X-Channels: 1
X-Bit-Depth: 16

<raw pcm bytes>

Errors and disconnect semantics

  • missing_required_field: input is missing or empty after trimming.
  • unsupported_response_format / response_format: the streaming request does not explicitly use pcm, or passes another audio format.
  • unsupported_stream / stream: stream_format is not audio/sse, or the resolved model does not support streaming.
  • unsupported_for_stream / sample_rate: the streaming request passes a non-zero sample_rate.
  • invalid_range / speed: speed is outside the 0.25-4 range.
  • unsupported_with_async / stream: stream=true and async=true are passed together.
  • unsupported_with_webhook / stream: the streaming request passes a non-empty webhook_url.
  • Request validation, model resolution, streaming-capability checks, and task-creation errors occur before the response starts and return a standard JSON error.
  • If SSE fails before speech.audio.done, the server sends an error data frame and closes the connection.
  • If raw PCM fails after response headers or audio bytes have been written, the server can only close the connection; returned PCM may be incomplete.
  • A client disconnect ends the current HTTP stream. Depending on the access path, it may cancel the upstream request or only the current subscription; clients must not assume that generation either always continues or is always canceled.
  • In the raw PCM mode, EOF alone does not prove that the audio is complete.

Next steps