Add batch streaming mode: assembly stream --from-stdin#181
Merged
Conversation
`assembly stream --from-stdin` reads a newline-delimited list of audio files/URLs on stdin and streams each as its own realtime session, in turn — distinct from `-` (raw PCM16 bytes on stdin). The realtime API handles one session at a time, so the list streams sequentially: each source gets a fresh StreamSession (its own transcript and --llm chain state) and is announced via a header (human/text) or a `source` NDJSON event (--json) before its turns. A per-source failure (bad path, missing ffmpeg, decode error) is recorded and the batch carries on, raising at the end so a script can trust the exit code; NotAuthenticated aborts the whole batch. Ctrl-C or a closed downstream pipe stops the batch cleanly (exit 0) — `StreamSession.run` grows a `handle_interrupt` flag so the batch driver owns those signals across the whole sequence instead of each session swallowing them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements batch streaming for the
assembly streamcommand, allowing users to pipe a list of audio file paths or URLs (one per line) to stdin and stream each as its own realtime session in turn.Summary
This adds the
--from-stdinflag toassembly stream, which reads a newline-delimited list of audio sources from stdin and streams each sequentially with its own transcript and LLM chain state. This complements the existing-(raw PCM) stdin mode and enables workflows likels *.wav | assembly stream --from-stdin.Key Changes
Core batch streaming logic:
stream_batch_sources()function inaai_cli/streaming/session.pythat orchestrates sequential streaming of multiple sources with per-source error handlingCLIError(file not found, decode failure) but aborts onNotAuthenticated(rejected API key applies to all sources)Command integration:
--from-stdinflag toassembly streamcommand_run_batch()and_collect_batch_sources()inaai_cli/commands/stream/_exec.pyto validate flag combinations and collect sources--sample,--system-audio,--device,--sample-rate,--show-codetranscribe --from-stdinbehavior)Streaming session updates:
StreamSession.run()and_guarded()withhandle_interruptparameter so batch driver owns Ctrl-C/pipe signals across the whole sequence (one Ctrl-C stops the batch, not just the current source)StreamRenderer.source()method to announce each source in the batch with position (e.g.,[2/3] file.wav)Event and output handling:
Sourceevent type toaai_cli/streaming/events.pyfor JSON mode segmentation{"type": "source", "source": "...", "index": 1, "total": 2}before each source's eventsValidation and error handling:
UsageErrorwith helpful suggestionNotAuthenticatedre-raises immediately to abort (one rejected key fails every source)Testing
Added comprehensive test suite (
tests/test_stream_batch.py) covering:sample=False(never coerced to hosted sample)Updated existing tests to include
from_stdin=Falsein defaults and added validation tests for flag conflicts.Notable Implementation Details
dict.fromkeys()to preserve order while removing duplicatesStreamSessionfrommake_session()so transcripts and LLM state don't bleed between sourcesopen_sourcecallback resolves sources withsample=Falseto ensure real files/URLs are used, never the hosted samplesourceevents marking boundarieshttps://claude.ai/code/session_01AA7v87iZNvfeGKhs2czBqq