Sambert server-sent events

更新时间:
复制 MD 格式

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

Important

Model Studio has released a workspace-specific domain for the China (Beijing) region: https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com. The new dedicated domain delivers superior performance and higher stability for inference requests. We recommend migrating from https://dashscope.aliyuncs.com to the new domain.

{WorkspaceId} is your workspace ID, which can be found on the Workspace Details page in the Model Studio console. The existing domain remains fully functional.

task-started

When the client sends the run-task command, the server returns a task-started event to indicate the task has started.

header.task_id string

The task ID generated by the client.

{
  "header": {
    "task_id": "2bf83b9a-baeb-4fda-8d9a-xxxxxxxxxxxx",
    "event": "task-started",
    "attributes": {}
  },
  "payload": {}
}

header.event string

The event type. Fixed value: task-started.

payload object

Empty object with no content.

result-generated

After the client sends text, the server streams result-generated events. Each event includes full timestamp data in output.sentence, with word-level and phoneme-level timestamps when the corresponding parameters are enabled.

header.task_id string

The task ID generated by the client.

{
  "header": {
    "task_id": "2bf83b9a-baeb-4fda-8d9a-xxxxxxxxxxxx",
    "event": "result-generated",
    "attributes": {}
  },
  "payload": {
    "output": {
      "sentence": {
        "begin_time": 0,
        "end_time": 1162,
        "words": [
          {
            "text": "Bed",
            "begin_time": 0,
            "end_time": 263,
            "phonemes": [
              {
                "begin_time": 0,
                "end_time": 119,
                "text": "ch_c",
                "tone": 2
              }
            ]
          }
        ]
      }
    },
    "usage": {
      "characters": 6
    }
  }
}

header.event string

The event type. Fixed value: result-generated.

payload.output object

The synthesized audio output.

Properties

sentence.begin_time integer

The begin timestamp of the sentence. Unit: milliseconds.

sentence.end_time integer

The end timestamp of the sentence. Unit: milliseconds.

sentence.words array

Word-level timestamps for each word in the sentence.

Element properties of words

text string

The text content of the word.

begin_time integer

The begin timestamp of the word in the audio. Unit: milliseconds.

end_time integer

The end timestamp of the word in the audio. Unit: milliseconds.

phonemes array (requires phoneme_timestamp_enabled)

Phoneme-level timestamps for each phoneme in the word.

Element properties of phonemes

text string

The phoneme text.

tone integer

The tone value.

begin_time integer

The begin timestamp of the phoneme. Unit: milliseconds.

end_time integer

The end timestamp of the phoneme. Unit: milliseconds.

payload.usage object

Billing usage for the current event.

Properties

characters integer

The cumulative billed character count up to the current event.

task-finished

When the task is complete, the server returns a task-finished event. The client can then close the WebSocket connection or reuse the connection for a new task.

header.task_id string

The task ID generated by the client.

{
  "header": {
    "task_id": "2bf83b9a-baeb-4fda-8d9a-xxxxxxxxxxxx",
    "event": "task-finished",
    "attributes": {
      "request_uuid": "0a9dba9e-d3a6-45a4-be6d-xxxxxxxxxxxx"
    }
  },
  "payload": {
    "usage": {
      "characters": 13
    }
  }
}

header.event string

The event type. Fixed value: task-finished.

payload.usage.characters integer

The cumulative billed character count up to the current event.

task-failed

When a task fails, the server returns a task-failed event. Close the WebSocket connection and handle the error.

header.task_id string

The task ID generated by the client.

{
  "header": {
    "task_id": "2bf83b9a-baeb-4fda-8d9a-xxxxxxxxxxxx",
    "event": "task-failed",
    "error_code": "InvalidParameter",
    "error_message": "[tts:]Engine return error code: 418",
    "attributes": {}
  },
  "payload": {}
}

header.event string

The event type. Fixed value: task-failed.

header.error_code string

The error code.

header.error_message string

The detailed error message.