[Feat]audio streaming input for async chunk (#3614)
Signed-off-by: CHEN <116010019@link.cuhk.edu.cn>
This commit is contained in:
1 parent
6f4bd3e45c
commit
5dfdf584dd
20 files changed
+536
-184
No files matched your search
@@ -1381,22 +1381,6 @@ async def streaming_video_chat(websocket: WebSocket):
|
||||
@router.websocket("/v1/realtime")
|
||||
async def realtime_websocket(websocket: WebSocket):
|
||||
"""WebSocket endpoint for OpenAI-style realtime interactions."""
|
||||
engine_client = getattr(websocket.app.state, "engine_client", None)
|
||||
if engine_client is not None and getattr(engine_client, "async_chunk", False):
|
||||
await websocket.accept()
|
||||
await websocket.send_json(
|
||||
{
|
||||
"type": "error",
|
||||
"error": (
|
||||
"The /v1/realtime API is not supported when async_chunk is enabled on the server. "
|
||||
"Use a stage configuration with async_chunk disabled and restart the server before using "
|
||||
"this endpoint."
|
||||
),
|
||||
"code": "unsupported",
|
||||
}
|
||||
)
|
||||
await websocket.close()
|
||||
return
|
||||
serving = getattr(websocket.app.state, "openai_serving_realtime", None)
|
||||
if serving is None:
|
||||
await websocket.accept()
|
||||
|
||||
@@ -120,7 +120,6 @@ class RealtimeConnection(VllmRealtimeConnection):
|
||||
full_text = ""
|
||||
prompt_token_ids_len = 0
|
||||
completion_tokens_len = 0
|
||||
last_prompt_token_ids_len = 0 # detect Stage-0 segment rollover
|
||||
self._realtime_audio_ref = None
|
||||
|
||||
# Coerce cumulative outputs to delta outputs; this ensures
|
||||
@@ -139,40 +138,26 @@ class RealtimeConnection(VllmRealtimeConnection):
|
||||
)
|
||||
|
||||
async for output in result_gen:
|
||||
# Handle delta texts; this is very similar to the client from vLLM
|
||||
if output.outputs and len(output.outputs) > 0:
|
||||
stage_id = getattr(output, "stage_id", None)
|
||||
if stage_id == 0 and output.outputs:
|
||||
first_output = output.outputs[0]
|
||||
new_token_ids = list(first_output.token_ids)
|
||||
new_tokens_len = len(new_token_ids)
|
||||
|
||||
cur_prompt_token_ids_len = len(output.prompt_token_ids or [])
|
||||
# Stage-0 segment rollover: buffer_realtime_audio may yield
|
||||
# multiple TokensPrompt segments and the second segment's
|
||||
# prompt_token_ids include the first segment's decoded output.
|
||||
# Clear accumulated full_text at the boundary so the
|
||||
# carried-over prefix is not duplicated in the final
|
||||
# TranscriptionDone.text.
|
||||
stage_id = getattr(output, "stage_id", None)
|
||||
if stage_id == 0 and cur_prompt_token_ids_len > last_prompt_token_ids_len > 0:
|
||||
full_text = ""
|
||||
last_prompt_token_ids_len = cur_prompt_token_ids_len
|
||||
|
||||
if not prompt_token_ids_len and output.prompt_token_ids:
|
||||
prompt_token_ids_len = len(output.prompt_token_ids)
|
||||
|
||||
if new_tokens_len:
|
||||
if new_token_ids:
|
||||
input_stream.put_nowait(new_token_ids)
|
||||
|
||||
if output.prompt_token_ids:
|
||||
prompt_token_ids_len = max(
|
||||
prompt_token_ids_len,
|
||||
len(output.prompt_token_ids),
|
||||
)
|
||||
|
||||
delta_text = first_output.text or ""
|
||||
full_text += delta_text
|
||||
completion_tokens_len += len(new_token_ids)
|
||||
|
||||
# append output to input if there was any delta text
|
||||
if delta_text:
|
||||
await self.send(TranscriptionDelta(delta=delta_text))
|
||||
|
||||
completion_tokens_len += new_tokens_len
|
||||
|
||||
# Handle audio chunking; this is Omni specific
|
||||
audio_chunks, sample_rate = self._extract_audio_chunks(output)
|
||||
|
||||
for chunk in audio_chunks:
|
||||
|
||||
Reference in new issue
Block a user