Skip to main content
CosyVoice

CosyVoice client events

CosyVoice real-time speech synthesis WebSocket client event reference

User guide: For model introduction and selection recommendations, see Speech synthesis.

run-task

Description: Starts a speech synthesis task and configures the model, voice, sample rate, and other parameters. When to send: Immediately after the WebSocket connection is established. Response event: The server returns a task-started event. Wait for this event before sending subsequent commands.
Example
{
    "header": {
        "action": "run-task",
        "task_id": "2bf83b9a-baeb-4fda-8d9a-xxxxxxxxxxxx",
        "streaming": "duplex"
    },
    "payload": {
        "task_group": "audio",
        "task": "tts",
        "function": "SpeechSynthesizer",
        "model": "cosyvoice-v3-flash",
        "parameters": {
            "text_type": "PlainText",
            "voice": "longanyang",
            "format": "mp3",
            "sample_rate": 22050,
            "volume": 50,
            "rate": 1.0,
            "pitch": 1.0,
            "enable_ssml": false
        },
        "input": {}
    }
}
object
body
required
Message header.
object
body
required
Request body.

continue-task

Description: Sends the text to synthesize. The text can be sent all at once or in multiple segments. When to send: After receiving the task-started event from the server. Limits:
  • Maximum of 20,000 characters per message
  • Maximum of 200,000 characters cumulatively
  • The send interval must not exceed 23 seconds; otherwise, the connection times out.
Example
{
    "header": {
        "action": "continue-task",
        "task_id": "2bf83b9a-baeb-4fda-8d9a-xxxxxxxxxxxx",
        "streaming": "duplex"
    },
    "payload": {
        "input": {
            "text": "Before my bed, moonlight shines bright, I suspect it's frost upon the ground."
        }
    }
}
object
body
required
Message header.
object
body
required
Request body.

finish-task

Description: Notifies the server that all text has been sent and requests task completion. When to send: Immediately after all text has been sent. Response event: The server returns a task-finished event.
Example
{
    "header": {
        "action": "finish-task",
        "task_id": "2bf83b9a-baeb-4fda-8d9a-xxxxxxxxxxxx",
        "streaming": "duplex"
    },
    "payload": {
        "input": {}
    }
}
object
body
required
Message header.
object
body
required
Request body.