Skip to content

Commit 4413d83

Browse files
committed
generate a silent audio file if no audio file appears
Signed-off-by: David Gao <[email protected]>
1 parent 292fc62 commit 4413d83

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

src/vllm_router/routers/main_router.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ async def get_engine_instances():
210210

211211
@main_router.get("/health")
212212
async def health() -> Response:
213-
"""Endpoint to check the health status of various components.
213+
"""
214+
Endpoint to check the health status of various components.
214215
215216
This function verifies the health of the service discovery module and
216217
the engine stats scraper. If either component is down, it returns a
@@ -247,7 +248,7 @@ async def health() -> Response:
247248

248249
@main_router.post("/v1/audio/transcriptions")
249250
async def audio_transcriptions(
250-
file: UploadFile = File(...),
251+
file: UploadFile | None = File(None),
251252
model: str = Form(...),
252253
prompt: str | None = Form(None),
253254
response_format: str | None = Form("json"),
@@ -276,7 +277,6 @@ async def audio_transcriptions(
276277
# logger.debug("=========files=========")
277278

278279
data = {
279-
"model": model,
280280
"language": language,
281281
}
282282

@@ -300,20 +300,12 @@ async def audio_transcriptions(
300300
logger.debug(endpoints)
301301
logger.debug("==== Total endpoints ====")
302302

303-
# TODO: right now is skipping label check in code for local testing
304-
endpoints = [
305-
ep
306-
for ep in endpoints
307-
if model in ep.model_names # that actually serve your model
303+
# filter the endpoints url by model name for transcriptions
304+
transcription_endpoints = [
305+
ep for ep in endpoints
306+
if model == ep.model_name and ep.model_label == "transcription"
308307
]
309308

310-
logger.debug("==== Discovered endpoints after filtering ====")
311-
logger.debug(endpoints)
312-
logger.debug("==== Discovered endpoints after filtering ====")
313-
314-
# filter the endpoints url for transcriptions
315-
transcription_endpoints = [ep for ep in endpoints if model in ep.model_names]
316-
317309
logger.debug("====List of transcription endpoints====")
318310
logger.debug(transcription_endpoints)
319311
logger.debug("====List of transcription endpoints====")

src/vllm_router/utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import requests
88
from fastapi.requests import Request
99
from starlette.datastructures import MutableHeaders
10+
import io
11+
import wave
1012

1113
from vllm_router.log import init_logger
1214

@@ -77,10 +79,22 @@ def get_test_payload(model_type: str):
7779
case ModelType.score:
7880
return {"encoding_format": "float", "text_1": "Test", "test_2": "Test2"}
7981
case ModelType.transcription:
82+
# Generate a 0.1 second silent audio file
83+
with io.BytesIO() as wav_buffer:
84+
with wave.open(wav_buffer, "wb") as wf:
85+
wf.setnchannels(1) # mono audio channel, standard configuration
86+
wf.setsampwidth(2) # 16 bit audio, common bit depth for wav file
87+
wf.setframerate(16000) # 16 kHz sample rate
88+
wf.writeframes(b"\x00\x00" * 1600) # 0.1 second of silence
89+
90+
# retrieves the generated wav bytes, return
91+
wav_bytes = wav_buffer.getvalue()
92+
8093
return {
81-
"file": "",
94+
"file": ("empty.wav", wav_bytes, "audio/wav"),
8295
}
8396

97+
8498
@staticmethod
8599
def get_all_fields():
86100
return [model_type.name for model_type in ModelType]

0 commit comments

Comments
 (0)