Skip to content

Commit 2f70230

Browse files
lishunyang12claude
andcommitted
fix: address review comments on Qwen3-TTS Gradio demo
- Fix SERVER_PID bug: background vllm-omni directly (not piped through tee) so $! captures the actual server PID, preventing orphaned processes on cleanup - Fix PCM format: handle raw PCM responses (no WAV header) by decoding as int16 samples at 24 kHz - Auto-detect task type: query /v1/models at startup and infer the task type from the model name, pre-selecting the correct radio button Signed-off-by: lishunyang <lishunyang12@163.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: lishunyang <lishunyang12@163.com>
1 parent 05278a2 commit 2f70230

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

examples/online_serving/qwen3_tts/gradio_demo.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@
3838
TASK_TYPES = ["CustomVoice", "VoiceDesign", "Base"]
3939

4040

41+
def detect_task_type(api_base: str) -> str | None:
42+
"""Auto-detect the task type from the model loaded on the server."""
43+
try:
44+
with httpx.Client(timeout=10.0) as client:
45+
resp = client.get(
46+
f"{api_base}/v1/models",
47+
headers={"Authorization": "Bearer EMPTY"},
48+
)
49+
if resp.status_code == 200:
50+
data = resp.json()
51+
models = data.get("data", [])
52+
if models:
53+
model_id = models[0].get("id", "")
54+
for task in TASK_TYPES:
55+
if task.lower() in model_id.lower():
56+
return task
57+
except Exception:
58+
pass
59+
return None
60+
61+
4162
def fetch_voices(api_base: str) -> list[str]:
4263
"""Fetch available voices from the server."""
4364
try:
@@ -148,6 +169,12 @@ def generate_speech(
148169

149170
# Decode audio response
150171
try:
172+
if response_format == "pcm":
173+
# PCM: raw 16-bit signed LE samples, no container header.
174+
# Qwen3-TTS outputs at 24 kHz by default.
175+
pcm_sample_rate = 24000
176+
audio_np = np.frombuffer(resp.content, dtype=np.int16).astype(np.float32) / 32767.0
177+
return (pcm_sample_rate, audio_np)
151178
audio_np, sample_rate = sf.read(io.BytesIO(resp.content))
152179
if audio_np.ndim > 1:
153180
audio_np = audio_np[:, 0]
@@ -189,6 +216,7 @@ def on_task_type_change(task_type: str):
189216

190217
def build_interface(api_base: str):
191218
"""Build the Gradio interface."""
219+
detected_task = detect_task_type(api_base)
192220
voices = fetch_voices(api_base)
193221

194222
css = """
@@ -199,7 +227,10 @@ def build_interface(api_base: str):
199227

200228
with gr.Blocks(css=css, title="Qwen3-TTS Demo") as demo:
201229
gr.Markdown("# Qwen3-TTS Online Serving Demo")
202-
gr.Markdown(f"**Server:** `{api_base}`")
230+
server_info = f"**Server:** `{api_base}`"
231+
if detected_task:
232+
server_info += f" &nbsp;|&nbsp; **Detected task:** `{detected_task}`"
233+
gr.Markdown(server_info)
203234

204235
with gr.Row():
205236
# Left column: inputs
@@ -213,7 +244,7 @@ def build_interface(api_base: str):
213244
with gr.Row():
214245
task_type = gr.Radio(
215246
choices=TASK_TYPES,
216-
value="CustomVoice",
247+
value=detected_task or "CustomVoice",
217248
label="Task Type",
218249
scale=2,
219250
)

examples/online_serving/qwen3_tts/run_gradio_demo.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ echo "=========================================="
106106
cleanup() {
107107
echo ""
108108
echo "Shutting down..."
109+
if [ -n "$LOG_TAIL_PID" ]; then
110+
kill "$LOG_TAIL_PID" 2>/dev/null || true
111+
fi
109112
if [ -n "$SERVER_PID" ]; then
110113
echo "Stopping vLLM server (PID: $SERVER_PID)..."
111114
kill "$SERVER_PID" 2>/dev/null || true
@@ -133,8 +136,11 @@ vllm-omni serve "$MODEL" \
133136
--gpu-memory-utilization 0.9 \
134137
--trust-remote-code \
135138
--enforce-eager \
136-
--omni 2>&1 | tee "$LOG_FILE" &
139+
--omni > "$LOG_FILE" 2>&1 &
137140
SERVER_PID=$!
141+
# Tail the log so the user can follow startup progress
142+
tail -f "$LOG_FILE" 2>/dev/null &
143+
LOG_TAIL_PID=$!
138144

139145
# Wait for server startup
140146
echo ""

0 commit comments

Comments
 (0)