[Feat]audio streaming input for async chunk (#3614)

Signed-off-by: CHEN <116010019@link.cuhk.edu.cn>
This commit is contained in:
ChenWenjing authored and GitHub committed 2026-05-31 17:39:25 +08:00
1 parent 6f4bd3e45c
commit 5dfdf584dd
20 files changed
+536 -184

No files matched your search

@@ -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: