Qwen-Audio-TTS のサーバーイベントリファレンス。タスク開始、文の合成、完了、失敗のフィールドと対応するリクエストを説明します。
イベントフロー
- run-task を送信してタスクを開始・設定し、task-started を待ちます。
task-startedの受信後、continue-task でテキストを送信しながら、result-generated と合成音声を受信します。- すべてのテキストを送信したら finish-task を送信し、task-finished まで残りの結果と音声を受信します。失敗したタスクは task-failed を返します。
result-generated は文のメタデータを返します。音声は別のチャネルを使用し、WebSocket ではバイナリフレーム、AOQ では Audio Track で転送します。接続、認証、音声転送については WebSocket API または AOQ 接続 をご参照ください。
task-started
タスクが正常に開始され、クライアントが合成するテキストを送信できることを示します。
重要task-started を受信してから continue-task を送信してください。 run-task はタスクの開始と設定に使用し、合成するテキストは continue-task で送信します。
headerobjecttask_idstringクライアントによって生成されたタスク ID。
eventstringイベントタイプ。固定値:task-started。
payloadobject空のオブジェクト。
{
"header": {
"action": "run-task",
"task_id": "f604f46b-5329-4520-a767-4ede894e0418",
"streaming": "duplex"
},
"payload": {
"input": {},
"task_group": "audio",
"task": "tts",
"function": "SpeechSynthesizer",
"model": "qwen-audio-3.1-tts-flash",
"parameters": {
"text_type": "PlainText",
"voice": "longanhuan_v3.1",
"format": "mp3",
"sample_rate": 22050
}
}
}
{
"header": {
"task_id": "f604f46b-5329-4520-a767-4ede894e0418",
"task_uuid": "573f4010c82040ad90d2a15e7d8afdbd",
"event": "task-started",
"attributes": {}
},
"payload": {}
}
result-generated
文の開始、音声データチャンクのマーカー、文の終了など、文のメタデータを返します。
重要sentence-end は文の合成完了を示し、タスク全体の終了ではありません。 タスクの終了は task-finished で判断します。音声は WebSocket のバイナリフレームまたは AOQ Audio Track で返されます。
headerobjecttask_idstringクライアントによって生成されたタスク ID。
eventstringイベントタイプ。固定値:result-generated。
payloadobjectoutputobject出力情報。
sentenceobjectindexinteger文インデックス。0 から始まります。
wordsarray単語レベルのタイムスタンプ配列。
textstring単語のテキスト内容。
begin_indexinteger文内の単語の開始文字インデックス。0 から始まります。
end_indexinteger文内の単語の終了文字インデックス。1 から始まります。
begin_timeinteger単語に対応する音声の開始時刻(ミリ秒単位)。
end_timeinteger単語に対応する音声の終了時刻(ミリ秒単位)。
typestringサブイベントタイプ。有効な値:
sentence-begin:文の開始。合成対象のテキストを返します。sentence-synthesis:オーディオフレームを示します。各イベントの直後に、WebSocket バイナリチャネルを通じて 1 つのオーディオフレームが送信されます。sentence-end:文の終了。テキスト内容と使用量情報(usage)を返します。
original_textstring合成用に分割された文のテキスト。
usageobject課金使用量。sentence-end イベントで返されます。
注記
usageは現在のタスクの累積使用量です。イベント間でusageを合計しないでください。 完了後はtask-finishedの最終累積使用量を使用します。- qwen-audio-3.1-tts-flash:入力と出力のトークン数に基づいて課金されます。使用量はそれぞれ
input_tokensとoutput_tokens、合計はtotal_tokensに示されます。 - qwen-audio-3.1-tts-plus:文字数(
characters)に基づいて課金されます。上記のトークン統計フィールドも返されます。 - qwen-audio-3.0-tts-plus、qwen-audio-3.0-tts-flash:文字数(
characters)に基づいて課金されます。
input_tokensintegerリクエストの入力トークン数。
output_tokensintegerリクエストの出力トークン数。
total_tokensinteger入力と出力のトークン数の合計。
charactersinteger課金対象文字数の累積数。
以下の例では、タスクの開始時に word_timestamp_enabled=true を設定しています。
sentence-begin
{
"header": {
"action": "continue-task",
"task_id": "51bcc1f0-b65f-484a-8f5f-5f22b2a90607",
"streaming": "duplex"
},
"payload": {
"input": {
"text": "Welcome to the speech synthesis service."
}
}
}
{
"header": {
"task_id": "51bcc1f0-b65f-484a-8f5f-5f22b2a90607",
"event": "result-generated",
"attributes": {
"x-dashscope-inner-response-type": "ws"
}
},
"payload": {
"output": {
"sentence": {
"index": 0,
"words": [
{
"text": "Welcome",
"begin_index": 0,
"end_index": 1,
"begin_time": 80,
"end_time": 400
},
{
"text": " to",
"begin_index": 1,
"end_index": 2,
"begin_time": 400,
"end_time": 640
},
{
"text": " the",
"begin_index": 2,
"end_index": 3,
"begin_time": 640,
"end_time": 720
},
{
"text": " speech",
"begin_index": 3,
"end_index": 4,
"begin_time": 720,
"end_time": 1040
},
{
"text": " synthesis",
"begin_index": 4,
"end_index": 5,
"begin_time": 1120,
"end_time": 1600
}
]
},
"type": "sentence-begin",
"original_text": "Welcome to the speech synthesis service.",
"normalized_text": "Welcome to the speech synthesis service."
}
}
}
sentence-synthesis
{
"header": {
"action": "continue-task",
"task_id": "51bcc1f0-b65f-484a-8f5f-5f22b2a90607",
"streaming": "duplex"
},
"payload": {
"input": {
"text": "Welcome to the speech synthesis service."
}
}
}
{
"header": {
"task_id": "51bcc1f0-b65f-484a-8f5f-5f22b2a90607",
"event": "result-generated",
"attributes": {
"x-dashscope-inner-response-type": "ws"
}
},
"payload": {
"output": {
"sentence": {
"index": 0,
"words": [
{
"text": "Welcome",
"begin_index": 0,
"end_index": 1,
"begin_time": 80,
"end_time": 400
},
{
"text": " to",
"begin_index": 1,
"end_index": 2,
"begin_time": 400,
"end_time": 640
},
{
"text": " the",
"begin_index": 2,
"end_index": 3,
"begin_time": 640,
"end_time": 720
},
{
"text": " speech",
"begin_index": 3,
"end_index": 4,
"begin_time": 720,
"end_time": 1040
},
{
"text": " synthesis",
"begin_index": 4,
"end_index": 5,
"begin_time": 1120,
"end_time": 1600
}
]
},
"type": "sentence-synthesis"
}
}
}
sentence-end
{
"header": {
"action": "continue-task",
"task_id": "51bcc1f0-b65f-484a-8f5f-5f22b2a90607",
"streaming": "duplex"
},
"payload": {
"input": {
"text": "Welcome to the speech synthesis service."
}
}
}
{
"header": {
"task_id": "51bcc1f0-b65f-484a-8f5f-5f22b2a90607",
"event": "result-generated",
"attributes": {
"x-dashscope-inner-response-type": "ws"
}
},
"payload": {
"output": {
"sentence": {
"index": 0,
"words": [
{
"text": "Welcome",
"begin_index": 0,
"end_index": 1,
"begin_time": 80,
"end_time": 400
},
{
"text": " to",
"begin_index": 1,
"end_index": 2,
"begin_time": 400,
"end_time": 640
},
{
"text": " the",
"begin_index": 2,
"end_index": 3,
"begin_time": 640,
"end_time": 720
},
{
"text": " speech",
"begin_index": 3,
"end_index": 4,
"begin_time": 720,
"end_time": 1040
},
{
"text": " synthesis",
"begin_index": 4,
"end_index": 5,
"begin_time": 1120,
"end_time": 1600
},
{
"text": " service.",
"begin_index": 5,
"end_index": 6,
"begin_time": 1680,
"end_time": 1920
}
]
},
"type": "sentence-end",
"original_text": "Welcome to the speech synthesis service.",
"normalized_text": "Welcome to the speech synthesis service."
},
"usage": {
"input_tokens": 7,
"output_tokens": 30,
"total_tokens": 37,
"characters": 40
}
}
}
task-finished
タスクが完了すると、サーバーは task-finished イベントを返します。その後、クライアントは WebSocket 接続を閉じるか、再利用して新しいタスクを開始できます。
headerobjecttask_idstringクライアントによって生成されたタスク ID。
eventstringイベントタイプ。固定値:task-finished。
payloadobjectusageobjectフィールドの意味は result-generated の usage と同じです。
{
"header": {
"action": "finish-task",
"task_id": "f604f46b-5329-4520-a767-4ede894e0418",
"streaming": "duplex"
},
"payload": {
"input": {}
}
}
{
"header": {
"task_id": "f604f46b-5329-4520-a767-4ede894e0418",
"event": "task-finished",
"attributes": {
"x-dashscope-inner-response-type": "ws"
}
},
"payload": {
"output": {},
"usage": {
"input_tokens": 7,
"output_tokens": 30,
"total_tokens": 37,
"characters": 40
}
}
}
task-failed
タスクが失敗すると、サーバーは task-failed イベントを返します。このイベントを受信すると、クライアントは WebSocket 接続を閉じ、エラーを処理する必要があります。
headerobjecttask_idstringクライアントによって生成されたタスク ID。
eventstringイベントタイプ。固定値:task-failed。
error_codestringエラーコード。
error_messagestring詳細なエラーメッセージ。
以下の例では未対応の音声形式を指定します。タスクを開始してテキストを送信すると、サーバーがエラーを返します。エラーコードとメッセージは失敗の原因により異なります。
{
"header": {
"action": "run-task",
"task_id": "7b091c3c-4b35-4c54-9b22-250749ce1b74",
"streaming": "duplex"
},
"payload": {
"input": {},
"task_group": "audio",
"task": "tts",
"function": "SpeechSynthesizer",
"model": "qwen-audio-3.1-tts-flash",
"parameters": {
"text_type": "PlainText",
"voice": "longanhuan_v3.1",
"format": "invalid-format",
"sample_rate": 22050
}
}
}
{
"header": {
"task_id": "7b091c3c-4b35-4c54-9b22-250749ce1b74",
"event": "task-failed",
"error_code": "InvalidParameter",
"error_message": "Request format is invalid!"
},
"payload": {}
}