Skip to main content
CosyVoice

CosyVoice HTTP API

The HTTP API for CosyVoice non-real-time speech synthesis, including non-streaming and SSE requests, request parameters, and response fields.

Endpoints

CosyVoice non-real-time speech synthesis over HTTP is available only in China North 2 (Beijing). Use a QwenCloud API key created for that region with the endpoint below. See Regions and endpoints. POST https://cn-beijing.maas.qwencloudapi.com/api/v1/services/audio/tts/SpeechSynthesizer

Request headers

ParameterTypeRequiredDescription
AuthorizationstringRequiredThe authentication token in the format Bearer $DASHSCOPE_API_KEY.
Content-TypestringRequiredSet to application/json.
X-DashScope-SSEstringOptionalSet to enable for streaming output. If omitted, the complete result is returned.

Examples

  • Non-streaming
  • Streaming
# China North 2 (Beijing). This model is available only in this region.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
curl -X POST "https://cn-beijing.maas.qwencloudapi.com/api/v1/services/audio/tts/SpeechSynthesizer" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "cosyvoice-v3-flash",
  "input": {
    "text": "我家的后面有一个很大的花园。",
    "voice": "longanyang",
    "format": "wav",
    "sample_rate": 24000
  }
}'
An SSE event may contain multiple data: lines. Combine all data: lines in the event before parsing JSON. Base64-decode and concatenate audio chunks in event order. The final frame has output.finish_reason=stop and returns the complete audio URL.

Request body

ParameterTypeRequiredDefaultDescription
modelstringRequired—The speech synthesis model ID. See Non-real-time speech synthesis for models and regions.
inputobjectRequired—The input parameters.
input.textstringRequired—Text to synthesize. Set enable_ssml=true for SSML input. LaTeX input requires no additional setting. See SSML and LaTeX for supported models, tags, and syntax.
input.voicestringRequired—The voice ID. For system voices, see the voice list. Create a custom voice with voice cloning or voice design, then synthesize with its bound target model.
input.formatstringOptionalmp3Audio encoding. Valid values: mp3, pcm, wav, and opus.
input.sample_rateintegerOptional22050Audio sample rate in Hz. Valid values: 8000, 12000, 16000, 22050, 24000, 44100, and 48000. With format=opus, only 8000, 12000, 16000, 24000, and 48000 are supported.
input.volumeintegerOptional50Volume. Range: [0, 100].
input.ratefloatOptional1.0Speaking rate. Range: [0.5, 2.0].
input.bit_rateintegerOptional32Audio bitrate in kbps. Range: [6, 510]. Applies only when format=opus.
input.pitchfloatOptional1.0Pitch. Range: [0.5, 2.0].
input.enable_ssmlbooleanOptional—Whether to enable SSML. See Usage limits for model, voice, and interface restrictions.
input.word_timestamp_enabledbooleanOptionalfalseWhether to return word-level timestamps. Streaming output only. Supports cloned voices of cosyvoice-v3.5-plus, cosyvoice-v3.5-flash, cosyvoice-v3-flash, cosyvoice-v3-plus, and cosyvoice-v2, and system voices marked as supported in the voice list. Cloned voices of other models are not supported.
input.seedintegerOptional0Random seed. Range: [0, 65535]. With the same model version, text, voice, and other parameters, the same seed reproduces the same synthesis result.
input.language_hintsarray[string]Optional—The target synthesis language. Only the first array element is processed. This is independent of the source language of a cloning sample. Set it for unexpected pronunciation of numbers, abbreviations, symbols, or less common languages. Language codes are listed below. For the cloning source language, see the voice cloning API.
input.instructionstringOptional—An instruction controlling dialect, emotion, or role. See Instruction control for model and voice support and usage.
input.enable_aigc_tagbooleanOptionalfalseWhether to embed an invisible AIGC identifier in WAV, MP3, or Opus audio. Supported only by cosyvoice-v3-flash, cosyvoice-v3-plus, and cosyvoice-v2.
input.aigc_propagatorstringOptionalQwenCloud account IDThe ContentPropagator field of the identifier, identifying the distributor. Applies only with enable_aigc_tag=true. Supported only by cosyvoice-v3-flash, cosyvoice-v3-plus, and cosyvoice-v2.
input.aigc_propagate_idstringOptionalRequest ID of this requestThe PropagateID field of the identifier, identifying this distribution operation. Applies only with enable_aigc_tag=true. Supported only by cosyvoice-v3-flash, cosyvoice-v3-plus, and cosyvoice-v2.
input.hot_fixobjectOptional—Text hotfix configuration. pronunciation customizes pronunciation for specified words. replace replaces specified text before synthesis. Not supported by cosyvoice-v2.
input.enable_markdown_filterbooleanOptionalfalseWhether to filter Markdown markers before synthesis. Supported only for cloned voices of cosyvoice-v3-flash.

Language codes

  • zh: Chinese
  • en: English
  • fr: French
  • de: German
  • ja: Japanese
  • ko: Korean
  • ru: Russian
  • pt: Portuguese
  • th: Thai
  • id: Indonesian
  • vi: Vietnamese
  • es: Spanish
  • it: Italian
  • ms: Malay
  • fil: Filipino
  • ar: Arabic
Example text hotfix configuration:
{
  "hot_fix": {
    "pronunciation": [
      {
        "天气": "tian1 qi4"
      }
    ],
    "replace": [
      {
        "今天": "金天"
      }
    ]
  }
}

Response body

ParameterTypeDescription
request_idstringThe unique request identifier.
outputobjectThe model output.
output.finish_reasonstringThe stop reason. null means synthesis is in progress; stop means synthesis is complete.
output.typestringReturned only for streaming output. sentence-begin marks the start of a sentence; sentence-synthesis marks an audio chunk, with multiple chunks possible per sentence; sentence-end marks the end and includes usage. Audio chunks and data frames correspond one to one. Append chunks to the same file in order.
output.original_textstringA sentence segmented from the input text. May be absent for the final sentence.
output.sentenceobjectSentence information.
output.sentence.indexintegerThe sentence index, starting at 0.
output.sentence.wordsarrayWords in the sentence and their timestamps.
output.sentence.words[].textstringA word or character.
output.sentence.words[].begin_indexintegerThe start position in the sentence, starting at 0.
output.sentence.words[].end_indexintegerThe end position in the sentence, starting at 1.
output.sentence.words[].begin_timeintegerThe audio start timestamp of the word, in milliseconds.
output.sentence.words[].end_timeintegerThe audio end timestamp of the word, in milliseconds.
output.audioobjectThe synthesized audio.
output.audio.datastringA Base64 audio chunk for streaming output. Empty for non-streaming output.
output.audio.urlstringThe complete audio file URL, valid for 24 hours.
output.audio.idstringThe synthesized audio identifier.
output.audio.expires_atintegerThe expiry timestamp of url.
usageobjectUsage information.
usage.charactersintegerCumulative billable characters.
  • Non-streaming
  • Streaming
{
  "output": {
    "audio": {
      "data": "",
      "id": "audio_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "expires_at": 1792079570,
      "url": "https://example.com/output.wav"
    },
    "finish_reason": "stop"
  },
  "usage": {
    "characters": 27
  },
  "request_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}