Client event reference for CosyVoice: run-task, continue-task, and finish-task fields, event order, and corresponding server events.
Event flow
- Send run-task to start and configure the task, then wait for task-started.
- After receiving
task-started, send text through continue-task while receiving result-generated events and synthesized audio. - After sending all text, send finish-task and keep receiving remaining results and audio until task-finished arrives. A failed task returns task-failed.
result-generated returns sentence metadata. Audio is transmitted separately as binary frames over WebSocket or through an Audio Track over AOQ. For connection setup, authentication, and audio transport, see WebSocket API or AOQ access.
run-task
Immediately after establishing the connection, the client sends run-task to start a speech synthesis task and set the model, voice, sample rate, and other parameters.
headerobjectRequiredactionstringRequiredThe command type. Set to
run-task.task_idstringRequiredA client-generated task ID in UUID format. This ID correlates subsequent events and must match the
task_id in the continue-task and finish-task commands.streamingstringRequiredSet to
duplex.payloadobjectRequiredtask_groupstringRequiredThe task group. Set to
audio.taskstringRequiredThe task type. Set to
tts.functionstringRequiredThe function type. Set to
SpeechSynthesizer.modelstringRequiredThe model name.
parametersobjectRequiredSpeech synthesis parameters.
text_typestringRequiredSet to
PlainText.voicestringRequiredThe voice used for speech synthesis.
- System voices: See CosyVoice Voice list
- Cloned voices: Custom voices created through voice cloning
- Custom voices: Custom voices created through voice design
formatstringOptionalThe audio encoding format.Valid values:
pcmwavmp3(default)opus
sample_rateintegerOptionalThe audio sample rate in Hz.Valid values: 8000, 16000, 22050 (default), 24000, 44100, 48000.
volumeintegerOptionalThe volume level.Default value: 50.Valid values: [0, 100].
ratefloatOptionalThe speech rate.Default value: 1.0.Valid values: [0.5, 2.0].
pitchfloatOptionalThe pitch.Default value: 1.0.Valid values: [0.5, 2.0].
bit_rateintegerOptionalThe audio bit rate in kbps. When the audio format is
mp3 or opus, use bit_rate to adjust the bit rate.Default value: 32.Valid values: [6, 510].enable_ssmlbooleanOptionalSpecifies whether to enable SSML.Default value: For the SSML usage restrictions (supported models, voices, and APIs), see Limitations.
false.When set to
true, only one continue-task command is allowed.word_timestamp_enabledbooleanOptionalSpecifies whether to enable word-level timestamps.Default value:
false.Available only in streaming output mode. Supported voices: cloned voices of cosyvoice-v3.5-plus, cosyvoice-v3.5-flash, cosyvoice-v3-flash, cosyvoice-v3-plus, cosyvoice-v2, and system voices marked as supported in CosyVoice Voice list. Cloned voices of other models do not support this feature.
seedintegerOptionalA random seed for controlling variation in the synthesis output. When the model version, text, voice, and other parameters are unchanged, using the same seed produces identical results.Default value: 0.Valid values: [0, 65535].
language_hintsarray[string]Optional- This parameter is an array, but the current version only processes the first element. Pass a single value.
- This parameter specifies the target language for speech synthesis. It's unrelated to the language of the audio sample used in voice cloning. To set the source language for a cloning task, see the voice cloning API reference.
pronunciation, abbreviation expansion, symbol reading, or minority-language synthesis doesn't meet expectations, use this parameter. For example:- Unexpected digit
pronunciation: "hello, this is 110" is read as "hello, this is one one zero" instead of the expected Chinesepronunciation - Inaccurate symbol
pronunciation: "@" is read as the Chinese equivalent instead of "at" - Poor minor language synthesis quality with unnatural results
Valid values
Valid values
zh: Chineseen: Englishfr: Frenchde: Germanja: Japaneseko: Koreanru: Russianpt: Portugueseth: Thaiid: Indonesianvi: Vietnamesees: Spanishit: Italianms: Malaysianfil: Filipinoar: Arabic
instructionstringOptionalSets an instruction to control dialect, emotion, or voice character during synthesis. For detailed usage, see Instruction control.
enable_aigc_tagbooleanOptionalSpecifies whether to embed an AIGC watermark in the generated audio. When set to
true, the watermark is embedded in audio files of supported formats (wav/mp3/opus).Default value: false.Only cosyvoice-v3-flash, cosyvoice-v3-plus, cosyvoice-v2 support this feature.
aigc_propagatorstringOptionalSets the
ContentPropagator field in the AIGC watermark, identifying the content propagator. Takes effect only when enable_aigc_tag is true.Default value: Alibaba Cloud UID.Only cosyvoice-v3-flash, cosyvoice-v3-plus, cosyvoice-v2 support this feature.
aigc_propagate_idstringOptionalSets the
PropagateID field in the AIGC watermark, uniquely identifying a specific propagation action. Takes effect only when enable_aigc_tag is true.Default value: The request ID of the current speech synthesis request.Only cosyvoice-v3-flash, cosyvoice-v3-plus, cosyvoice-v2 support this feature.
enable_markdown_filterbooleanOptionalcosyvoice-v2 does not support this feature.
false.Valid values:true: Enable Markdown filteringfalse: Disable Markdown filtering
inputobjectRequiredSet to an empty object
{}. Send the text to synthesize through the continue-task command.Request:
Response:
continue-task
After receiving task-started, the client sends continue-task to submit text for synthesis. Text can be sent all at once or in sequential segments.
headerobjectRequiredactionstringRequiredThe command type. Set to
continue-task.task_idstringRequiredThe task ID in UUID format. Must match the
task_id in run-task.streamingstringRequiredSet to
duplex.payloadobjectRequiredinputobjectRequiredContains the text to synthesize.
textstringRequiredThe text to synthesize. Maximum of 20,000 characters per message and 200,000 characters cumulatively.
The send interval must not exceed 23 seconds; otherwise, the connection times out.
Request:
Response:
finish-task
Immediately after sending all text, the client sends finish-task to notify the server that text input is complete and request task completion. To cancel the current synthesis turn, set directive to cancel in input.
headerobjectRequiredactionstringRequiredThe command type. Set to
finish-task.task_idstringRequiredThe task ID in UUID format. Must match the
task_id in run-task.streamingstringRequiredSet to
duplex.payloadobjectRequiredinputobjectRequiredSet to
{} for normal task completion. Include directive to cancel the current synthesis turn.directivestringOptionalControls how the task ends. Currently only
cancel is supported. When set to cancel, the current synthesis turn is canceled and the server immediately returns a task-finished event without producing further audio.After cancellation, you can start a new synthesis task on the same WebSocket connection by sending a new run-task event without reconnecting.- Normal completion
- Cancel task
Request:
Response: