hearing.capture¶
Audio capture and channel handling for the hearing pipeline.
This module owns turning an audio source into per-channel float arrays, and the
all-important channel split: mic and system audio are kept on separate channels
so that “who is local” is known for free (see the hearing-diarization skill for
what we do with that, and hearing-audio-capture for the macOS mechanics —
BlackHole + Aggregate Device, or Core Audio taps).
The generic, channel-agnostic conditioning (decode, down-mix, resample, energy) now
lives in scribed.audio and is re-exported here for backward compatibility —
hearing owns only the multi-channel / “me vs them” concerns.
Functions
|
Split a multi-channel array into per- |
Classes
|
A batch |
|
Live macOS capture from an audio device (the milestone-2 capture source). |
|
A streaming |
- class hearing.capture.ChannelSplitFileCapture(path, mic_channels=(0,), system_channels=(1,))[source]¶
Bases:
objectA batch
CaptureSourceover an audio file.Reads the file once and yields
(channel, mono_frames)for each channel present. The live counterpart (device/tap) implements the same interface; swapping it in is the only change needed to go live — see thehearing-live-pipelineskill.Typical use (needs a real audio file, so it is not run as a doctest):
ChannelSplitFileCapture("meeting.wav").frames()
- async astream()[source]¶
Stream the file’s channels in one shot (whole clip per channel).
Provided so a file satisfies the async
CaptureSourcetoo; for a realistic block-by-block live simulation useStreamingFileCapture.- Return type:
AsyncIterator[tuple[Channel,ndarray]]
- class hearing.capture.DeviceCapture(device=None, block_ms=200, mic_channels=(0, 1), system_channels=(2, 3), sample_rate=48000, channels_count=4)[source]¶
Bases:
objectLive macOS capture from an audio device (the milestone-2 capture source).
Point this at an Aggregate Device that combines your microphone and BlackHole (so mic and system audio land on separate, non-mixed channels — see the
hearing-audio-captureskill for the Audio MIDI Setup). Reads multi-channel blocks and splits them into mic/system channels.Requires
pip install 'hearing[capture]'(sounddevice). Needs real audio hardware to exercise; constructing it is cheap (the device opens inastream). For a hardware-free run of the live loop, useStreamingFileCapture.- async astream()[source]¶
Open the device and yield
(channel, block)blocks until cancelled.- Return type:
AsyncIterator[tuple[Channel,ndarray]]
- class hearing.capture.StreamingFileCapture(path, block_ms=200, realtime=False, mic_channels=(0,), system_channels=(1,))[source]¶
Bases:
objectA streaming
CaptureSourceover a file.Yields
(channel, block)inblock_mschunks, time-ordered across channels, so the live pipeline can be exercised end-to-end without a mic or BlackHole. Withrealtime=Trueit paces playback in real time (for demos); the default streams as fast as possible (for tests).- async astream()[source]¶
Yield
(channel, block)blocks, all channels per time step.- Return type:
AsyncIterator[tuple[Channel,ndarray]]
- hearing.capture.split_channels(data, *, mic_channels=(0,), system_channels=(1,))[source]¶
Split a multi-channel array into per-
Channelmono arrays.An aggregate device does not mix — mic lands on one set of channels and system audio on another — so we can slice the columns apart. A mono file (or single-column) has no split; it is returned as
{Channel.MIXED: ...}.- Parameters:
- Return type:
- Returns:
Mapping from
Channelto a mono float32 array. Channels whose indices are out of range are silently omitted.