catap 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- catap-0.2.0/CHANGELOG.md +40 -0
- catap-0.2.0/LICENSE +21 -0
- catap-0.2.0/PKG-INFO +278 -0
- catap-0.2.0/README.md +250 -0
- catap-0.2.0/pyproject.toml +89 -0
- catap-0.2.0/src/catap/__init__.py +87 -0
- catap-0.2.0/src/catap/__main__.py +6 -0
- catap-0.2.0/src/catap/_devtools/__init__.py +1 -0
- catap-0.2.0/src/catap/_devtools/test_tone.py +155 -0
- catap-0.2.0/src/catap/_devtools/tone.py +220 -0
- catap-0.2.0/src/catap/bindings/__init__.py +1 -0
- catap-0.2.0/src/catap/bindings/_audiotoolbox.py +340 -0
- catap-0.2.0/src/catap/bindings/_coreaudio.py +215 -0
- catap-0.2.0/src/catap/bindings/device.py +299 -0
- catap-0.2.0/src/catap/bindings/hardware.py +41 -0
- catap-0.2.0/src/catap/bindings/process.py +167 -0
- catap-0.2.0/src/catap/bindings/tap.py +123 -0
- catap-0.2.0/src/catap/bindings/tap_description.py +254 -0
- catap-0.2.0/src/catap/cli.py +354 -0
- catap-0.2.0/src/catap/py.typed +0 -0
- catap-0.2.0/src/catap/recorder.py +956 -0
- catap-0.2.0/src/catap/session.py +502 -0
catap-0.2.0/CHANGELOG.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.2.0] - 2026-04-21
|
|
6
|
+
|
|
7
|
+
- Initial public release of `catap`.
|
|
8
|
+
- Added device stream discovery so taps can target a specific input/output stream.
|
|
9
|
+
- Added discovery of existing process taps and the ability to record from them.
|
|
10
|
+
- Added shared-tap support: create, extend, and delete shared taps from the core lab demo.
|
|
11
|
+
- Raised clearer errors for stale shared taps and preserved zero-tap device stream metadata.
|
|
12
|
+
- Hardened audio recorder concurrency and cleanup lifecycle for free-threaded Python builds.
|
|
13
|
+
- Consolidated recorder structs and unified the cleanup cascade.
|
|
14
|
+
- Moved helper tone tooling into an internal devtools package and added regression coverage.
|
|
15
|
+
- Added worker queue latency profiling and restored synthetic profiler compatibility.
|
|
16
|
+
- Expanded the core lab demo with recording playback controls, helper tone device selection, shared-tap workflows, and bench-style chrome.
|
|
17
|
+
- Bumped supported Python floor metadata to include 3.14.
|
|
18
|
+
- Slimmed the README and split implementation notes into `docs/`.
|
|
19
|
+
|
|
20
|
+
## [0.1.0] - 2026-04-17
|
|
21
|
+
|
|
22
|
+
- Initial private release of `catap`.
|
|
23
|
+
- Added a CLI for listing audio processes and recording app or system audio.
|
|
24
|
+
- Added a Python API for process taps and WAV recording.
|
|
25
|
+
- Streamed WAV output during recording so long captures do not accumulate unbounded RAM.
|
|
26
|
+
- Improved macOS-only runtime errors and permission guidance.
|
|
27
|
+
- `find_process_by_name` now prefers exact application-name and bundle-ID matches over partial matches, and raises `AmbiguousAudioProcessError` (new public export) when a query matches multiple processes.
|
|
28
|
+
- `list_audio_processes` propagates Core Audio failures instead of silently returning an empty list.
|
|
29
|
+
- Recorder now uses a bounded work queue so the Core Audio callback no longer blocks or grows memory without bound; dropped buffers are surfaced as a `RuntimeError` on stop.
|
|
30
|
+
- Recorder queue bounds are now configurable via `max_pending_buffers` on the low-level recorder and the high-level session helpers.
|
|
31
|
+
- Recorder output-file lifecycle is hardened: failed WAV setup closes the underlying file, and the output file is closed in the worker's teardown.
|
|
32
|
+
- Recorder startup no longer touches the destination WAV path until Core Audio startup succeeds, preventing failed starts from clobbering existing files.
|
|
33
|
+
- Session and recorder setup now reject target-less "streaming" configurations unless an `on_data` callback is supplied.
|
|
34
|
+
- Recorder now uses Core Audio `AudioConverter` for the float32 -> int16 WAV path, improving worker throughput while changing the exact int16 rounding/clipping semantics to match Core Audio.
|
|
35
|
+
- CLI distinguishes output-file errors (bad path, unwritable directory) from permission errors when a recording fails to start.
|
|
36
|
+
- Added an opt-in integration smoke test that performs a short real recording and validates the resulting WAV file.
|
|
37
|
+
- Consolidated internal Core Audio bindings into a single `_coreaudio` module for easier maintenance.
|
|
38
|
+
- Added internal AudioToolbox bindings and synthetic profiling coverage for `AudioConverter` / `ExtAudioFile` comparisons.
|
|
39
|
+
- Flattened the package layout by moving `AudioRecorder` to `catap.recorder` and removing the one-file `catap.core` package.
|
|
40
|
+
- Added a Tkinter demo app for manually exercising the browser, high-level recording flows, callback streaming, and low-level tap/recorder APIs.
|
catap-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Sage Betko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
catap-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: catap
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Python wrapper for Apple's Core Audio Tap API
|
|
5
|
+
Keywords: audio,macos,core-audio,recording,tap,capture
|
|
6
|
+
Author: Sage Betko
|
|
7
|
+
Author-email: Sage Betko <sage.betko@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: MacOS X
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Capture/Recording
|
|
19
|
+
Requires-Dist: pyobjc-core>=11.0 ; sys_platform == 'darwin'
|
|
20
|
+
Requires-Dist: pyobjc-framework-cocoa>=11.0 ; sys_platform == 'darwin'
|
|
21
|
+
Requires-Dist: pyobjc-framework-coreaudio>=11.0 ; sys_platform == 'darwin'
|
|
22
|
+
Requires-Python: >=3.12
|
|
23
|
+
Project-URL: Homepage, https://github.com/sbetko/catap
|
|
24
|
+
Project-URL: Documentation, https://github.com/sbetko/catap#readme
|
|
25
|
+
Project-URL: Repository, https://github.com/sbetko/catap
|
|
26
|
+
Project-URL: Issues, https://github.com/sbetko/catap/issues
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# catap
|
|
30
|
+
|
|
31
|
+
A Python wrapper for Apple's Core Audio Tap API (macOS 14.2+). Capture audio
|
|
32
|
+
from any application without loopback drivers or virtual audio devices.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install catap # macOS 14.2+, Python 3.12+
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`catap` is macOS-only. On other platforms, imports raise an `ImportError`.
|
|
41
|
+
|
|
42
|
+
## Quick start
|
|
43
|
+
|
|
44
|
+
**CLI**
|
|
45
|
+
```bash
|
|
46
|
+
catap record Safari -d 10 -o safari.wav # record an app for 10 seconds
|
|
47
|
+
catap record --system -d 10 -o mix.wav # record the full system mix
|
|
48
|
+
catap list-apps # see what's producing audio
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**API**
|
|
52
|
+
```python
|
|
53
|
+
from catap import record_process
|
|
54
|
+
|
|
55
|
+
session = record_process("Safari", output_path="safari.wav")
|
|
56
|
+
session.record_for(10)
|
|
57
|
+
|
|
58
|
+
print(f"Recorded {session.duration_seconds:.2f}s")
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Highlights
|
|
62
|
+
|
|
63
|
+
- **Per-app capture** by name, bundle ID, or PID, with uniqueness-aware partial matches.
|
|
64
|
+
- **System capture** with optional app-level exclusions.
|
|
65
|
+
- **Silent capture** — mute an app's playback while you record it, with documented semantics for each mute mode.
|
|
66
|
+
- **Shared taps** — attach to a tap another tool already created, without taking ownership.
|
|
67
|
+
- **Device-targeted taps** — route capture through a specific hardware output stream.
|
|
68
|
+
- **Streaming callbacks** — hand PCM buffers to your own code instead of writing WAV.
|
|
69
|
+
- **Bounded, recoverable I/O** — long captures don't grow RAM without bound; dropped buffers surface as errors on stop.
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
### Command Line
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# List applications producing audio
|
|
77
|
+
catap list-apps
|
|
78
|
+
|
|
79
|
+
# List all audio processes (including idle ones)
|
|
80
|
+
catap list-apps --all
|
|
81
|
+
|
|
82
|
+
# Record from an application (exact or uniquely partial name match, case-insensitive)
|
|
83
|
+
catap record Safari -o ~/safari_audio.wav
|
|
84
|
+
|
|
85
|
+
# Record for a specific duration
|
|
86
|
+
catap record Spotify -d 30 -o ~/song.wav
|
|
87
|
+
|
|
88
|
+
# Record with app muted (capture only, no playback)
|
|
89
|
+
catap record Spotify --mute -d 60 -o ~/silent_capture.wav
|
|
90
|
+
|
|
91
|
+
# Record system audio
|
|
92
|
+
catap record --system -d 30 -o ~/system_audio.wav
|
|
93
|
+
|
|
94
|
+
# Record system audio (optionally excluding apps)
|
|
95
|
+
catap record --system -e Music -e Zoom -d 30 -o ~/system_audio.wav
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Python API
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from catap import record_process
|
|
102
|
+
|
|
103
|
+
# High-level API: catap manages tap creation, startup, shutdown, and cleanup.
|
|
104
|
+
session = record_process("Safari", output_path="output.wav")
|
|
105
|
+
session.record_for(5)
|
|
106
|
+
|
|
107
|
+
print(f"Recorded {session.duration_seconds:.2f} seconds")
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
If you use `on_data=...`, the callback runs on catap's background worker
|
|
111
|
+
thread so the Core Audio callback can stay lightweight.
|
|
112
|
+
|
|
113
|
+
If you want to control the recording lifetime yourself, use the session as a
|
|
114
|
+
context manager:
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
import time
|
|
118
|
+
from catap import record_process
|
|
119
|
+
|
|
120
|
+
with record_process("Safari", output_path="output.wav", mute=False) as session:
|
|
121
|
+
time.sleep(5)
|
|
122
|
+
|
|
123
|
+
print(f"Recorded {session.duration_seconds:.2f} seconds")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
If you want streaming-only mode, pass `on_data=...` and omit `output_path`.
|
|
127
|
+
|
|
128
|
+
By default, `catap` queues up to 256 pending audio buffers before treating a
|
|
129
|
+
slow writer or callback as a capture failure. You can tune this with
|
|
130
|
+
`max_pending_buffers=...` on `record_process`, `record_system_audio`,
|
|
131
|
+
`RecordingSession`, or `AudioRecorder`.
|
|
132
|
+
|
|
133
|
+
If a process query matches more than one audio process, `catap` reports the
|
|
134
|
+
candidate processes instead of picking one arbitrarily.
|
|
135
|
+
|
|
136
|
+
### Mute Behavior
|
|
137
|
+
|
|
138
|
+
For `record_process(..., mute=True)`, the app stays muted for the lifetime of
|
|
139
|
+
the recording session. The two underlying modes (`MUTED` and
|
|
140
|
+
`MUTED_WHEN_TAPPED`) have different lifecycle semantics — see
|
|
141
|
+
[`docs/mute-behavior.md`](docs/mute-behavior.md) for empirical probe results
|
|
142
|
+
and when each mode transitions between audible and inaudible.
|
|
143
|
+
|
|
144
|
+
### Low-level API
|
|
145
|
+
|
|
146
|
+
For advanced use cases, the low-level API is still available:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from catap import (
|
|
150
|
+
AudioRecorder,
|
|
151
|
+
TapDescription,
|
|
152
|
+
TapMuteBehavior,
|
|
153
|
+
create_process_tap,
|
|
154
|
+
destroy_process_tap,
|
|
155
|
+
find_process_by_name,
|
|
156
|
+
list_audio_taps,
|
|
157
|
+
record_tap,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
process = find_process_by_name("Safari")
|
|
161
|
+
print(f"Found: {process.name} (PID: {process.pid})")
|
|
162
|
+
|
|
163
|
+
tap_desc = TapDescription.stereo_mixdown_of_processes([process.audio_object_id])
|
|
164
|
+
tap_desc.name = "My Recording"
|
|
165
|
+
tap_desc.mute_behavior = TapMuteBehavior.UNMUTED # or MUTED
|
|
166
|
+
|
|
167
|
+
tap_id = create_process_tap(tap_desc)
|
|
168
|
+
|
|
169
|
+
recorder = AudioRecorder(tap_id, "output.wav")
|
|
170
|
+
recorder.start()
|
|
171
|
+
|
|
172
|
+
import time
|
|
173
|
+
time.sleep(5)
|
|
174
|
+
|
|
175
|
+
recorder.stop()
|
|
176
|
+
print(f"Recorded {recorder.duration_seconds:.2f} seconds")
|
|
177
|
+
|
|
178
|
+
destroy_process_tap(tap_id)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
If another app has already created a non-private tap, you can discover it and
|
|
182
|
+
attach a recorder without taking ownership of the tap itself:
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
from catap import list_audio_taps, record_tap
|
|
186
|
+
|
|
187
|
+
tap = next(tap for tap in list_audio_taps() if tap.name == "Shared Mix")
|
|
188
|
+
session = record_tap(tap, output_path="shared-mix.wav")
|
|
189
|
+
session.record_for(5)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Device-targeted taps can be built directly from discovered hardware streams:
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
from catap import TapDescription, find_process_by_name, list_audio_devices
|
|
196
|
+
|
|
197
|
+
process = find_process_by_name("Safari")
|
|
198
|
+
device = next(device for device in list_audio_devices() if device.is_default_output)
|
|
199
|
+
stream = device.output_streams[0]
|
|
200
|
+
|
|
201
|
+
tap_desc = TapDescription.of_processes_for_device_stream(
|
|
202
|
+
[process.audio_object_id],
|
|
203
|
+
stream,
|
|
204
|
+
)
|
|
205
|
+
tap_desc.name = "Safari on default speakers"
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Permissions
|
|
209
|
+
|
|
210
|
+
Core Audio Tap requires audio capture permissions. The first time you record, macOS will prompt for permission.
|
|
211
|
+
|
|
212
|
+
If you run from a terminal (for example `uv run catap record Spotify`), macOS attributes audio capture to that terminal app.
|
|
213
|
+
Grant permission to Terminal, iTerm, or whichever host app is launching `catap`.
|
|
214
|
+
|
|
215
|
+
### Permission Troubleshooting
|
|
216
|
+
|
|
217
|
+
If recording fails with permission errors:
|
|
218
|
+
|
|
219
|
+
1. Check System Settings > Privacy & Security > Screen & System Audio Recording
|
|
220
|
+
2. Ensure the app launching `catap` has permission (Terminal, iTerm, etc.)
|
|
221
|
+
3. Retry recording from the same terminal app after granting access
|
|
222
|
+
|
|
223
|
+
## How It Works
|
|
224
|
+
|
|
225
|
+
1. **Process Enumeration**: Uses Core Audio's `kAudioHardwarePropertyProcessObjectList` to find audio processes
|
|
226
|
+
2. **Tap Creation**: Creates a `CATapDescription` via PyObjC and calls `AudioHardwareCreateProcessTap`
|
|
227
|
+
3. **Aggregate Device**: Wraps the tap in an aggregate device (required by Core Audio to read audio data)
|
|
228
|
+
4. **Audio Capture**: Registers an `AudioDeviceIOProc` callback to receive audio buffers
|
|
229
|
+
5. **WAV Output**: Uses Core Audio `AudioConverter` to convert float32 audio to 16-bit PCM before writing WAV output
|
|
230
|
+
|
|
231
|
+
For Core Audio implementation notes (header locations, tap property codes,
|
|
232
|
+
aggregate-device dictionary keys, references), see
|
|
233
|
+
[`docs/core-audio-notes.md`](docs/core-audio-notes.md).
|
|
234
|
+
|
|
235
|
+
## Interactive lab
|
|
236
|
+
|
|
237
|
+
For a tkinter lab that exercises the tap and recorder surface — process
|
|
238
|
+
browsing, mute modes, callback streaming, shared-tap attachment,
|
|
239
|
+
device-stream-targeted taps, and a built-in helper tone launcher — run:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
uv sync --group dev
|
|
243
|
+
uv run python scripts/catap_core_lab.py
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Development
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
git clone https://github.com/sbetko/catap.git
|
|
250
|
+
cd catap
|
|
251
|
+
uv sync --group dev
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Quality checks
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
uv run --group dev ruff check .
|
|
258
|
+
uv run --group dev ty check --error-on-warning src tests
|
|
259
|
+
uv run --group dev pytest
|
|
260
|
+
uv run --group dev python -m build
|
|
261
|
+
uv run --group dev twine check dist/*
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Optional integration smoke test
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
CATAP_RUN_INTEGRATION=1 uv run --group dev pytest -m integration
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
This opt-in smoke test exercises the real macOS Core Audio bridge without
|
|
271
|
+
making the default test suite flaky. It covers both process enumeration and a
|
|
272
|
+
short real recording that verifies tap startup, shutdown, and WAV finalization.
|
|
273
|
+
|
|
274
|
+
See [`RELEASE.md`](RELEASE.md) for the release checklist.
|
|
275
|
+
|
|
276
|
+
## License
|
|
277
|
+
|
|
278
|
+
MIT
|
catap-0.2.0/README.md
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# catap
|
|
2
|
+
|
|
3
|
+
A Python wrapper for Apple's Core Audio Tap API (macOS 14.2+). Capture audio
|
|
4
|
+
from any application without loopback drivers or virtual audio devices.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install catap # macOS 14.2+, Python 3.12+
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
`catap` is macOS-only. On other platforms, imports raise an `ImportError`.
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
**CLI**
|
|
17
|
+
```bash
|
|
18
|
+
catap record Safari -d 10 -o safari.wav # record an app for 10 seconds
|
|
19
|
+
catap record --system -d 10 -o mix.wav # record the full system mix
|
|
20
|
+
catap list-apps # see what's producing audio
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**API**
|
|
24
|
+
```python
|
|
25
|
+
from catap import record_process
|
|
26
|
+
|
|
27
|
+
session = record_process("Safari", output_path="safari.wav")
|
|
28
|
+
session.record_for(10)
|
|
29
|
+
|
|
30
|
+
print(f"Recorded {session.duration_seconds:.2f}s")
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Highlights
|
|
34
|
+
|
|
35
|
+
- **Per-app capture** by name, bundle ID, or PID, with uniqueness-aware partial matches.
|
|
36
|
+
- **System capture** with optional app-level exclusions.
|
|
37
|
+
- **Silent capture** — mute an app's playback while you record it, with documented semantics for each mute mode.
|
|
38
|
+
- **Shared taps** — attach to a tap another tool already created, without taking ownership.
|
|
39
|
+
- **Device-targeted taps** — route capture through a specific hardware output stream.
|
|
40
|
+
- **Streaming callbacks** — hand PCM buffers to your own code instead of writing WAV.
|
|
41
|
+
- **Bounded, recoverable I/O** — long captures don't grow RAM without bound; dropped buffers surface as errors on stop.
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
### Command Line
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# List applications producing audio
|
|
49
|
+
catap list-apps
|
|
50
|
+
|
|
51
|
+
# List all audio processes (including idle ones)
|
|
52
|
+
catap list-apps --all
|
|
53
|
+
|
|
54
|
+
# Record from an application (exact or uniquely partial name match, case-insensitive)
|
|
55
|
+
catap record Safari -o ~/safari_audio.wav
|
|
56
|
+
|
|
57
|
+
# Record for a specific duration
|
|
58
|
+
catap record Spotify -d 30 -o ~/song.wav
|
|
59
|
+
|
|
60
|
+
# Record with app muted (capture only, no playback)
|
|
61
|
+
catap record Spotify --mute -d 60 -o ~/silent_capture.wav
|
|
62
|
+
|
|
63
|
+
# Record system audio
|
|
64
|
+
catap record --system -d 30 -o ~/system_audio.wav
|
|
65
|
+
|
|
66
|
+
# Record system audio (optionally excluding apps)
|
|
67
|
+
catap record --system -e Music -e Zoom -d 30 -o ~/system_audio.wav
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Python API
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from catap import record_process
|
|
74
|
+
|
|
75
|
+
# High-level API: catap manages tap creation, startup, shutdown, and cleanup.
|
|
76
|
+
session = record_process("Safari", output_path="output.wav")
|
|
77
|
+
session.record_for(5)
|
|
78
|
+
|
|
79
|
+
print(f"Recorded {session.duration_seconds:.2f} seconds")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
If you use `on_data=...`, the callback runs on catap's background worker
|
|
83
|
+
thread so the Core Audio callback can stay lightweight.
|
|
84
|
+
|
|
85
|
+
If you want to control the recording lifetime yourself, use the session as a
|
|
86
|
+
context manager:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import time
|
|
90
|
+
from catap import record_process
|
|
91
|
+
|
|
92
|
+
with record_process("Safari", output_path="output.wav", mute=False) as session:
|
|
93
|
+
time.sleep(5)
|
|
94
|
+
|
|
95
|
+
print(f"Recorded {session.duration_seconds:.2f} seconds")
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
If you want streaming-only mode, pass `on_data=...` and omit `output_path`.
|
|
99
|
+
|
|
100
|
+
By default, `catap` queues up to 256 pending audio buffers before treating a
|
|
101
|
+
slow writer or callback as a capture failure. You can tune this with
|
|
102
|
+
`max_pending_buffers=...` on `record_process`, `record_system_audio`,
|
|
103
|
+
`RecordingSession`, or `AudioRecorder`.
|
|
104
|
+
|
|
105
|
+
If a process query matches more than one audio process, `catap` reports the
|
|
106
|
+
candidate processes instead of picking one arbitrarily.
|
|
107
|
+
|
|
108
|
+
### Mute Behavior
|
|
109
|
+
|
|
110
|
+
For `record_process(..., mute=True)`, the app stays muted for the lifetime of
|
|
111
|
+
the recording session. The two underlying modes (`MUTED` and
|
|
112
|
+
`MUTED_WHEN_TAPPED`) have different lifecycle semantics — see
|
|
113
|
+
[`docs/mute-behavior.md`](docs/mute-behavior.md) for empirical probe results
|
|
114
|
+
and when each mode transitions between audible and inaudible.
|
|
115
|
+
|
|
116
|
+
### Low-level API
|
|
117
|
+
|
|
118
|
+
For advanced use cases, the low-level API is still available:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from catap import (
|
|
122
|
+
AudioRecorder,
|
|
123
|
+
TapDescription,
|
|
124
|
+
TapMuteBehavior,
|
|
125
|
+
create_process_tap,
|
|
126
|
+
destroy_process_tap,
|
|
127
|
+
find_process_by_name,
|
|
128
|
+
list_audio_taps,
|
|
129
|
+
record_tap,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
process = find_process_by_name("Safari")
|
|
133
|
+
print(f"Found: {process.name} (PID: {process.pid})")
|
|
134
|
+
|
|
135
|
+
tap_desc = TapDescription.stereo_mixdown_of_processes([process.audio_object_id])
|
|
136
|
+
tap_desc.name = "My Recording"
|
|
137
|
+
tap_desc.mute_behavior = TapMuteBehavior.UNMUTED # or MUTED
|
|
138
|
+
|
|
139
|
+
tap_id = create_process_tap(tap_desc)
|
|
140
|
+
|
|
141
|
+
recorder = AudioRecorder(tap_id, "output.wav")
|
|
142
|
+
recorder.start()
|
|
143
|
+
|
|
144
|
+
import time
|
|
145
|
+
time.sleep(5)
|
|
146
|
+
|
|
147
|
+
recorder.stop()
|
|
148
|
+
print(f"Recorded {recorder.duration_seconds:.2f} seconds")
|
|
149
|
+
|
|
150
|
+
destroy_process_tap(tap_id)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
If another app has already created a non-private tap, you can discover it and
|
|
154
|
+
attach a recorder without taking ownership of the tap itself:
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from catap import list_audio_taps, record_tap
|
|
158
|
+
|
|
159
|
+
tap = next(tap for tap in list_audio_taps() if tap.name == "Shared Mix")
|
|
160
|
+
session = record_tap(tap, output_path="shared-mix.wav")
|
|
161
|
+
session.record_for(5)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Device-targeted taps can be built directly from discovered hardware streams:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from catap import TapDescription, find_process_by_name, list_audio_devices
|
|
168
|
+
|
|
169
|
+
process = find_process_by_name("Safari")
|
|
170
|
+
device = next(device for device in list_audio_devices() if device.is_default_output)
|
|
171
|
+
stream = device.output_streams[0]
|
|
172
|
+
|
|
173
|
+
tap_desc = TapDescription.of_processes_for_device_stream(
|
|
174
|
+
[process.audio_object_id],
|
|
175
|
+
stream,
|
|
176
|
+
)
|
|
177
|
+
tap_desc.name = "Safari on default speakers"
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Permissions
|
|
181
|
+
|
|
182
|
+
Core Audio Tap requires audio capture permissions. The first time you record, macOS will prompt for permission.
|
|
183
|
+
|
|
184
|
+
If you run from a terminal (for example `uv run catap record Spotify`), macOS attributes audio capture to that terminal app.
|
|
185
|
+
Grant permission to Terminal, iTerm, or whichever host app is launching `catap`.
|
|
186
|
+
|
|
187
|
+
### Permission Troubleshooting
|
|
188
|
+
|
|
189
|
+
If recording fails with permission errors:
|
|
190
|
+
|
|
191
|
+
1. Check System Settings > Privacy & Security > Screen & System Audio Recording
|
|
192
|
+
2. Ensure the app launching `catap` has permission (Terminal, iTerm, etc.)
|
|
193
|
+
3. Retry recording from the same terminal app after granting access
|
|
194
|
+
|
|
195
|
+
## How It Works
|
|
196
|
+
|
|
197
|
+
1. **Process Enumeration**: Uses Core Audio's `kAudioHardwarePropertyProcessObjectList` to find audio processes
|
|
198
|
+
2. **Tap Creation**: Creates a `CATapDescription` via PyObjC and calls `AudioHardwareCreateProcessTap`
|
|
199
|
+
3. **Aggregate Device**: Wraps the tap in an aggregate device (required by Core Audio to read audio data)
|
|
200
|
+
4. **Audio Capture**: Registers an `AudioDeviceIOProc` callback to receive audio buffers
|
|
201
|
+
5. **WAV Output**: Uses Core Audio `AudioConverter` to convert float32 audio to 16-bit PCM before writing WAV output
|
|
202
|
+
|
|
203
|
+
For Core Audio implementation notes (header locations, tap property codes,
|
|
204
|
+
aggregate-device dictionary keys, references), see
|
|
205
|
+
[`docs/core-audio-notes.md`](docs/core-audio-notes.md).
|
|
206
|
+
|
|
207
|
+
## Interactive lab
|
|
208
|
+
|
|
209
|
+
For a tkinter lab that exercises the tap and recorder surface — process
|
|
210
|
+
browsing, mute modes, callback streaming, shared-tap attachment,
|
|
211
|
+
device-stream-targeted taps, and a built-in helper tone launcher — run:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
uv sync --group dev
|
|
215
|
+
uv run python scripts/catap_core_lab.py
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Development
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
git clone https://github.com/sbetko/catap.git
|
|
222
|
+
cd catap
|
|
223
|
+
uv sync --group dev
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Quality checks
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
uv run --group dev ruff check .
|
|
230
|
+
uv run --group dev ty check --error-on-warning src tests
|
|
231
|
+
uv run --group dev pytest
|
|
232
|
+
uv run --group dev python -m build
|
|
233
|
+
uv run --group dev twine check dist/*
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Optional integration smoke test
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
CATAP_RUN_INTEGRATION=1 uv run --group dev pytest -m integration
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
This opt-in smoke test exercises the real macOS Core Audio bridge without
|
|
243
|
+
making the default test suite flaky. It covers both process enumeration and a
|
|
244
|
+
short real recording that verifies tap startup, shutdown, and WAV finalization.
|
|
245
|
+
|
|
246
|
+
See [`RELEASE.md`](RELEASE.md) for the release checklist.
|
|
247
|
+
|
|
248
|
+
## License
|
|
249
|
+
|
|
250
|
+
MIT
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "catap"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "Python wrapper for Apple's Core Audio Tap API"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Sage Betko", email = "sage.betko@gmail.com" }
|
|
10
|
+
]
|
|
11
|
+
requires-python = ">=3.12"
|
|
12
|
+
keywords = ["audio", "macos", "core-audio", "recording", "tap", "capture"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 4 - Beta",
|
|
15
|
+
"Environment :: MacOS X",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Operating System :: MacOS :: MacOS X",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Programming Language :: Python :: 3.14",
|
|
22
|
+
"Topic :: Multimedia :: Sound/Audio :: Capture/Recording",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"pyobjc-core>=11.0; sys_platform == 'darwin'",
|
|
26
|
+
"pyobjc-framework-Cocoa>=11.0; sys_platform == 'darwin'",
|
|
27
|
+
"pyobjc-framework-CoreAudio>=11.0; sys_platform == 'darwin'",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[dependency-groups]
|
|
31
|
+
dev = [
|
|
32
|
+
"build>=1.4.0",
|
|
33
|
+
"pytest>=9.0.2",
|
|
34
|
+
"pytest-cov>=7.0.0",
|
|
35
|
+
"ruff>=0.15.5",
|
|
36
|
+
"twine>=6.2.0",
|
|
37
|
+
"ty>=0.0.21",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/sbetko/catap"
|
|
42
|
+
Documentation = "https://github.com/sbetko/catap#readme"
|
|
43
|
+
Repository = "https://github.com/sbetko/catap"
|
|
44
|
+
Issues = "https://github.com/sbetko/catap/issues"
|
|
45
|
+
|
|
46
|
+
[project.scripts]
|
|
47
|
+
catap = "catap.cli:main"
|
|
48
|
+
|
|
49
|
+
[build-system]
|
|
50
|
+
requires = ["uv_build>=0.10.8,<0.11.0"]
|
|
51
|
+
build-backend = "uv_build"
|
|
52
|
+
|
|
53
|
+
[tool.uv.build-backend]
|
|
54
|
+
source-include = ["CHANGELOG.md"]
|
|
55
|
+
|
|
56
|
+
[tool.ruff]
|
|
57
|
+
src = ["src", "tests"]
|
|
58
|
+
|
|
59
|
+
[tool.ruff.lint]
|
|
60
|
+
select = ["E", "F", "I", "B", "UP", "SIM", "RUF", "PERF", "PT"]
|
|
61
|
+
|
|
62
|
+
[tool.ruff.lint.isort]
|
|
63
|
+
combine-as-imports = true
|
|
64
|
+
|
|
65
|
+
[tool.pytest.ini_options]
|
|
66
|
+
addopts = "-q --strict-markers"
|
|
67
|
+
testpaths = ["tests"]
|
|
68
|
+
markers = [
|
|
69
|
+
"integration: opt-in tests that exercise the real macOS Core Audio bridge",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
[tool.coverage.report]
|
|
73
|
+
omit = [
|
|
74
|
+
"src/catap/__main__.py",
|
|
75
|
+
"src/catap/_devtools/*",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
[tool.vulture]
|
|
79
|
+
paths = ["src", "tests", "scripts"]
|
|
80
|
+
sort_by_size = true
|
|
81
|
+
ignore_names = [
|
|
82
|
+
"client_data",
|
|
83
|
+
"device",
|
|
84
|
+
"input_time",
|
|
85
|
+
"now",
|
|
86
|
+
"output_time",
|
|
87
|
+
"pytestmark",
|
|
88
|
+
"traceback",
|
|
89
|
+
]
|