[Bugfix][Qwen3-TTS] Handle codec generations that exhaust their token budget (#6728)

Signed-off-by: Sy03 <1370724210@qq.com>
This commit is contained in:
Sy03 authored and GitHub committed 2026-08-29 08:59:05 -07:00
1 parent 676a35fa8b
commit 3adee400a0
14 files changed
+551 -43

No files matched your search

@@ -1,3 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
"""WebSocket handler for streaming text input TTS.
Accepts text incrementally via WebSocket, buffers it until input.done, and
@@ -329,7 +332,7 @@ class OmniStreamingSpeechHandler:
request_id = None
try:
if config.stream_audio:
request_id, generator, _ = await self._speech_service._prepare_speech_generation(request)
request_id, generator, tts_params = await self._speech_service._prepare_speech_generation(request)
if config.word_timestamps:
total_bytes = await self._stream_audio_with_alignments(
websocket=websocket,
@@ -339,9 +342,16 @@ class OmniStreamingSpeechHandler:
utterance_index=utterance_index,
sentence_index=sentence_index,
language=config.language,
tts_params=tts_params,
)
else:
async with aclosing(self._speech_service._generate_pcm_chunks(generator, request_id)) as stream:
async with aclosing(
self._speech_service._generate_pcm_chunks(
generator,
request_id,
tts_params=tts_params,
)
) as stream:
async for chunk in stream:
total_bytes += len(chunk)
await websocket.send_bytes(chunk)
@@ -367,6 +377,7 @@ class OmniStreamingSpeechHandler:
await self._send_error(
websocket,
f"Generation failed for utterance {utterance_index}, sentence {sentence_index}: {e}",
partial_audio=total_bytes > 0,
)
finally:
try:
@@ -392,6 +403,7 @@ class OmniStreamingSpeechHandler:
utterance_index: int,
sentence_index: int,
language: str | None = None,
tts_params: dict | None = None,
) -> int:
"""Stream PCM as JSON ``audio.chunk`` frames, aligned per sentence.
@@ -438,6 +450,7 @@ class OmniStreamingSpeechHandler:
generator,
request_id,
include_sample_rate=True,
tts_params=tts_params,
collect=collect,
)
) as stream:
@@ -463,14 +476,15 @@ class OmniStreamingSpeechHandler:
return total_bytes
@staticmethod
async def _send_error(websocket: WebSocket, message: str) -> None:
async def _send_error(websocket: WebSocket, message: str, *, partial_audio: bool = False) -> None:
"""Send an error message to the client."""
try:
await websocket.send_json(
{
"type": "error",
"message": message,
}
)
payload: dict[str, object] = {
"type": "error",
"message": message,
}
if partial_audio:
payload.update(partial_audio=True, action="discard")
await websocket.send_json(payload)
except Exception:
pass # Connection may already be closed; safe to ignore