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+

Installation

pip install audiotap

The wheel includes a prebuilt libaudiotap.dylib — no C compiler or make step needed.

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. Installed as a console script:

audiotap-capture-both [duration_seconds]
ffplay -f f32le -ar 48000 -ac 2 system.pcm
ffplay -f f32le -ar 48000 -ac 1 mic.pcm

Development

For working on the bindings themselves, uv is used for dependency management:

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

# Install dependencies
make sync

# Run the capture_both example
make capture_both

# Run tests
make test

Architecture

src/audiotap/__init__.py              High-level API (SystemTap, MicTap, Permission)
src/audiotap/_bindings.py             Low-level ctypes bindings to libaudiotap.dylib
src/audiotap/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.2.tar.gz (16.5 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.2-py3-none-macosx_14_0_arm64.whl (15.1 kB view details)

Uploaded Python 3macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: audiotap-0.0.2.tar.gz
  • Upload date:
  • Size: 16.5 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.2.tar.gz
Algorithm Hash digest
SHA256 e3320b2c87c70cee59afea4aea18797f9a82553b7f57a31cf2a657ff5f2b13bd
MD5 a14e9cb33f0f86d6bb17d9ff572169a4
BLAKE2b-256 771cec672108390da30ba435b55be2d6ea1437765cd440bea5a2268becf0f3ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for audiotap-0.0.2.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.2-py3-none-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for audiotap-0.0.2-py3-none-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f17173d04639ce072ea03cf5f17f99a4df060ed7a64a30a503b77a6b33ac2cbb
MD5 d5d93346715c9cdc40a2f6c29bd18183
BLAKE2b-256 f5e60fa121c5b39a586ff52c269a726a8b51384fe0e12c689146215db8376e11

See more details on using hashes here.

Provenance

The following attestation bundles were made for audiotap-0.0.2-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