Add --save-audio flag to record streamed PCM to WAV#186
Merged
Conversation
Tee exactly the bytes sent to the streaming API to a 16-bit mono WAV while transcribing, without altering the live transcript. This lets a downstream consumer (e.g. an ensemble that compares live turns against an async re-transcribe) keep the audio without owning capture itself. - New streaming/record.py: tee_wav() writes each chunk at the source's true rate and yields it onward; the header is patched on exhaustion or early close (Ctrl-C) so a partial recording is still a valid WAV. validate_target() rejects a missing parent dir up front, before credentials. - StreamSession gains save_audio; the single-source path tees in stream_one. - Rejected combinations (clear usage errors): --system-audio/--system-audio-only (two streams can't share one file), --from-stdin (batch is many sources), and --show-code (generated SDK code doesn't tee). https://claude.ai/code/session_01MiPAW6mr1pYQuAE123HGxD
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.
Adds a
--save-audioflag toassembly streamthat tees the streamed PCM audio to a WAV file while transcribing, enabling callers to keep a verbatim recording of the audio sent to the streaming API without owning capture themselves.Key changes
New
aai_cli/streaming/record.pymodule: Implementstee_wav()generator that yields PCM chunks unchanged while writing them to disk as a 16-bit mono WAV, andvalidate_target()to check the output path's parent directory exists before streaming starts.--save-audioCLI option: Added toaai_cli/commands/stream/__init__.pywith validation that the path is writable and the parent directory exists.Validation & mutual exclusivity:
--save-audiowith--from-stdin(can't tee multiple sources to one file)--save-audiowith--system-audio(mic and system streams can't share one file)--save-audiowith--show-code(generated SDK code doesn't tee audio)Integration into streaming session:
StreamSession.stream_one()wraps the audio iterable withtee_wav()whensave_audiois set, writing at the source's true sample rate.Comprehensive test coverage:
tee_wav()behavior (unchanged passthrough, valid WAV output, early close handling, empty streams, unopenable paths)Implementation details
The tee is implemented as a generator that writes each chunk to disk and yields it onward unchanged, ensuring the API receives exactly what was captured. The WAV header's length fields are patched on generator close (including via
GeneratorExiton Ctrl-C), so even interrupted runs leave valid, playable WAV files. The recording is always mono 16-bit PCM at the source's sample rate, matching the shape the streaming API receives.https://claude.ai/code/session_01MiPAW6mr1pYQuAE123HGxD