Skip to main content

Python bindings for libaudiotap — capture system audio and microphone on macOS

Project description

audiotap Python bindings

Python package for capturing system audio and microphone input on macOS, built on top of libaudiotap.

Audio is delivered as interleaved float32 PCM bytes via callbacks using ctypes to load libaudiotap.dylib.

Requirements

  • macOS 14.2+ (Sonoma)
  • Python 3.10+
  • uv
  • The C library must be built first (make -C ..)

Building

# Build the C shared library (required)
make -C .. build/libaudiotap.dylib

# Install dependencies
make sync

# Run the capture_both example (default target)
make

Usage

import audiotap

def on_audio(samples: bytes, frame_count: int, channels: int, host_time: int):
    # samples is interleaved float32 PCM
    ...

# Capture from microphone
with audiotap.MicTap(callback=on_audio, sample_rate=48000, channels=1) as tap:
    tap.start()
    ...

System audio capture works the same way with SystemTap:

tap = audiotap.SystemTap(
    callback=on_audio,
    sample_rate=48000,
    channels=2,
    pids=None,   # None = all processes
    mute=False,  # True to silence speakers
)

API

Type / Function Description
SystemTap(callback, sample_rate, channels, *, pids, mute) Capture system audio output
MicTap(callback, sample_rate, channels) Capture microphone input
.start() Begin capturing audio
.stop() Pause capture without releasing resources
.destroy() Stop and release all resources
.running True if the tap is currently capturing
request_mic_permission() Prompt for microphone permission (blocking)
mic_permission_status() Check microphone permission (non-blocking)
error_string(status) Human-readable message for an OSStatus code

Both tap classes support context managers (with) and raise AudioTapError on failure.

Examples

capture_both

Records system audio (stereo) and microphone (mono) to raw PCM files at 48 kHz:

make capture_both
ffplay -f f32le -ar 48000 -ac 2 system.pcm
ffplay -f f32le -ar 48000 -ac 1 mic.pcm

Architecture

src/audiotap/__init__.py   High-level API (SystemTap, MicTap, Permission)
src/audiotap/_bindings.py  Low-level ctypes bindings to libaudiotap.dylib
examples/capture_both.py   Audio capture to PCM files (port of C example)
tests/test_audiotap.py     High-level API tests (mocked)
tests/test_bindings.py     Bindings-layer tests

The library uses ctypes to load libaudiotap.dylib at runtime. Audio callbacks from the C library are bridged through a ctypes function pointer trampoline that converts the raw float pointer into Python bytes before delivering to the user callback.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

audiotap-0.0.1.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

audiotap-0.0.1-py3-none-macosx_14_0_arm64.whl (13.1 kB view details)

Uploaded Python 3macOS 14.0+ ARM64

File details

Details for the file audiotap-0.0.1.tar.gz.

File metadata

  • Download URL: audiotap-0.0.1.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for audiotap-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4c83033e57cffc3276804debf1ef7708135f7a9eb4af4340e677caac85624f26
MD5 b42f7deda3db0d4fc1e0b275d9d94398
BLAKE2b-256 8b63204b4bbc3caba5e669d7fd79925206cdbc49789f449cb448bcdde8ff4188

See more details on using hashes here.

Provenance

The following attestation bundles were made for audiotap-0.0.1.tar.gz:

Publisher: release.yml on graphaelli/audiotap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file audiotap-0.0.1-py3-none-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for audiotap-0.0.1-py3-none-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 023b1c7ed6405bdb361c9c538b6ad0c8f28d3c347a83eb6f29f7ff73fe83913d
MD5 5b5a8226a7c7c5b748d042612b795ed3
BLAKE2b-256 a16e320e53c5b59f3c22302368bd68a90753d13afacc35d3f781c7929872ea69

See more details on using hashes here.

Provenance

The following attestation bundles were made for audiotap-0.0.1-py3-none-macosx_14_0_arm64.whl:

Publisher: release.yml on graphaelli/audiotap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page