Skip to main content

Cross-platform process-level audio capture library

Project description

๐Ÿ“ก ProcTap

Cross-Platform Per-Process Audio Capture

PyPI version Python versions Downloads Platform

Build wheels License: MIT Code style GitHub stars


ProcTap is a Python library for per-process audio capture with platform-specific backends.

Capture audio from a specific process only โ€” without system sounds or other app audio mixed in. Ideal for VRChat, games, DAWs, browsers, and AI audio analysis pipelines.

Platform Support

Platform Status Backend Notes
Windows โœ… Fully Supported WASAPI (C++ native) Windows 10/11 (20H1+)
Linux โœ… Fully Supported PipeWire Native / PulseAudio Per-process isolation, auto-fallback (v0.3.0+)
macOS ๐Ÿงช Experimental Core Audio Process Tap macOS 14.4+ (Sonoma) required

* Linux is fully supported with PipeWire/PulseAudio (v0.3.0+). macOS support is experimental (see requirements).


๐Ÿš€ Features

  • ๐ŸŽง Capture audio from a single target process (VRChat, games, browsers, Discord, DAWs, streaming tools, etc.)

  • ๐ŸŒ Cross-platform architecture โ†’ Windows (fully supported) | Linux (fully supported, v0.3.0+) | macOS (experimental, 14.4+)

  • โšก Platform-optimized backends โ†’ Windows: ActivateAudioInterfaceAsync (modern WASAPI) โ†’ Linux: PipeWire Native API / PulseAudio (fully supported, v0.3.0+) โ†’ macOS: Core Audio Process Tap API (macOS 14.4+)

  • ๐Ÿงต Low-latency, thread-safe audio engine โ†’ 44.1 kHz / stereo / 16-bit PCM format (Windows)

  • ๐Ÿ Python-friendly high-level API

    • Callback-based streaming
    • Async generator streaming (async for)
  • ๐Ÿ”Œ Native extensions for high-performance โ†’ C++ extension on Windows for optimal throughput


๐Ÿ“ฆ Installation

From PyPI:

pip install proc-tap

Platform-specific dependencies are automatically installed:

  • Windows: No additional dependencies
  • Linux: pulsectl is automatically installed, but you also need system packages:
    # Ubuntu/Debian
    sudo apt-get install pulseaudio-utils
    
    # Fedora/RHEL
    sudo dnf install pulseaudio-utils
    

Optional: High-Quality Audio Resampling (74% faster / 3.8x speedup for sample rate conversion):

pip install proc-tap[hq-resample]

Performance: With libsamplerate, resampling achieves 0.66ms per 10ms chunk (vs 2.6ms with scipy-only).

Compatibility Notes:

  • โœ… Python 3.10-3.12: Works on all platforms
  • โœ… Linux/macOS + Python 3.13+: Should work (you can try it!)
  • โš ๏ธ Windows + Python 3.13+: May fail to build (as of 2025-01)
    • If it fails, the library automatically falls back to scipy's polyphase filtering
    • Still provides excellent audio quality, just 74% slower for resampling
    • You can still try installing - if it works, great! If not, no harm done.

๐Ÿ“š Read the Full Documentation for detailed guides and API reference.

From TestPyPI (for testing pre-releases):

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ proctap

From Source:

git clone https://github.com/m96-chan/ProcTap
cd ProcTap
pip install -e .

๐ŸŽฌ CLI Usage (Pipe to FFmpeg)

ProcTap includes a CLI for piping audio directly to FFmpeg or other tools:

# Pipe to FFmpeg (MP3 encoding) - Direct command
proctap --pid 12345 --stdout | ffmpeg -f s16le -ar 48000 -ac 2 -i pipe:0 output.mp3

# Or using python -m
python -m proctap --pid 12345 --stdout | ffmpeg -f s16le -ar 48000 -ac 2 -i pipe:0 output.mp3

# Using process name instead of PID
proctap --name "VRChat.exe" --stdout | ffmpeg -f s16le -ar 48000 -ac 2 -i pipe:0 output.mp3

# FLAC encoding (lossless)
proctap --pid 12345 --stdout | ffmpeg -f s16le -ar 48000 -ac 2 -i pipe:0 output.flac

# Custom sample rate and mono output
proctap --pid 12345 --sample-rate 44100 --channels 1 --stdout | ffmpeg -f s16le -ar 44100 -ac 1 -i pipe:0 output.wav

CLI Options:

Option Description
--pid PID Process ID to capture (required if --name not used)
--name NAME Process name to capture (e.g., VRChat.exe or VRChat)
--stdout Output raw PCM to stdout for piping (required)
--sample-rate RATE Sample rate in Hz (default: 48000)
--channels {1,2} Number of channels: 1=mono, 2=stereo (default: 2)
--verbose Enable verbose logging to stderr

Finding Process IDs:

# Windows
tasklist | findstr "VRChat"

# Linux/macOS
ps aux | grep VRChat

FFmpeg Format Arguments:

The CLI outputs raw PCM in s16le (signed 16-bit little-endian) format by default, but can be customized via --sample-rate and --channels options. FFmpeg needs these arguments:

  • -f s16le: PCM format
  • -ar RATE: Sample rate (must match --sample-rate, default 48000)
  • -ac CHANNELS: Number of channels (must match --channels, default 2)
  • -i pipe:0: Read from stdin

๐Ÿ›  Requirements

Windows (Fully Supported):

  • Windows 10 / 11 (20H1 or later)
  • Python 3.10+
  • WASAPI support
  • No admin privileges required

Linux (Fully Supported - v0.3.0+):

  • Linux with PulseAudio or PipeWire
  • Python 3.10+
  • Auto-detection: Automatically selects best available backend
  • Native PipeWire API (in development, experimental):
    • libpipewire-0.3-dev: sudo apt-get install libpipewire-0.3-dev
    • Target latency: ~2-5ms (when fully implemented)
    • Auto-selected when available (may fall back to subprocess)
  • PipeWire subprocess:
    • pw-record: install with sudo apt-get install pipewire-media-session
  • PulseAudio fallback:
    • pulsectl library: automatically installed
    • parec command: sudo apt-get install pulseaudio-utils
  • โœ… Per-process isolation using null-sink strategy
  • โœ… Graceful fallback chain: Native โ†’ PipeWire subprocess โ†’ PulseAudio

macOS (Experimental):

  • macOS 14.4 (Sonoma) or later
  • Python 3.10+
  • Swift CLI helper binary (proctap-macos)
  • Audio capture permission
  • โš ๏ธ EXPERIMENTAL: Core Audio Process Tap API support implemented
  • โš ๏ธ REQUIREMENT: Requires macOS 14.4+ for Process Tap API

๐Ÿงฐ Basic Usage (Callback API)

from proctap import ProcTap, StreamConfig

def on_chunk(pcm: bytes, frames: int):
    print(f"Received {len(pcm)} bytes ({frames} frames)")

pid = 12345  # Target process ID

tap = ProcTap(pid, StreamConfig(), on_data=on_chunk)
tap.start()

input("Recording... Press Enter to stop.\n")

tap.close()

๐Ÿ” Async Usage (Async Generator)

import asyncio
from proctap import ProcTap

async def main():
    tap = ProcTap(pid=12345)
    tap.start()

    async for chunk in tap.iter_chunks():
        print(f"PCM chunk size: {len(chunk)} bytes")

asyncio.run(main())

๐Ÿ“„ API Overview

class ProcTap

Control Methods:

Method Description
start() Start WASAPI per-process capture
stop() Stop capture
close() Release native resources

Data Access:

Method Description
iter_chunks() Async generator yielding PCM chunks
read(timeout=1.0) Synchronous: read one chunk (blocking)

Properties:

Property Type Description
is_running bool Check if capture is active
pid int Get target process ID
config StreamConfig Get stream configuration

Utility Methods:

Method Description
set_callback(callback) Change or remove audio callback
get_format() Get audio format info (dict)

Audio Format

Native Backend Format (Windows WASAPI, hardcoded in C++):

Parameter Value Description
Sample Rate 44,100 Hz CD quality (fixed in C++)
Channels 2 Stereo (fixed in C++)
Bit Depth 16-bit PCM format (fixed in C++)

Output Format Conversion (v0.2.1+):

The StreamConfig class controls the output format through automatic conversion:

  • Native format โ†’ converted to match your StreamConfig settings
  • Supports sample rate conversion (e.g., 44.1kHz โ†’ 48kHz)
  • Supports channel conversion (mono โ†” stereo)
  • Supports bit depth conversion (8/16/24/32-bit)
  • Zero overhead when formats match (automatic bypass)

Example:

# Get audio as 48kHz mono 24-bit
config = StreamConfig(sample_rate=48000, channels=1, width=3)
tap = ProcTap(pid, config=config)

๐ŸŽฏ Use Cases

  • ๐ŸŽฎ Record audio from one game only
  • ๐Ÿ•ถ Capture VRChat audio cleanly (without system sounds)
  • ๐ŸŽ™ Feed high-SNR audio into AI recognition models
  • ๐Ÿ“น Alternative to OBS "Application Audio Capture"
  • ๐ŸŽง Capture DAW/app playback for analysis tools

๐Ÿ“š Example: Save to WAV

from proctap import ProcTap
import wave

pid = 12345

wav = wave.open("output.wav", "wb")
wav.setnchannels(2)
wav.setsampwidth(2)  # 16-bit PCM
wav.setframerate(44100)  # Native format is 44.1 kHz

def on_data(pcm, frames):
    wav.writeframes(pcm)

with ProcTap(pid, on_data=on_data):
    input("Recording... Press Enter to stop.\n")

wav.close()

๐Ÿ“š Example: Synchronous Read API

from proctap import ProcTap

tap = ProcTap(pid=12345)
tap.start()

try:
    while True:
        chunk = tap.read(timeout=1.0)  # Blocking read
        if chunk:
            print(f"Got {len(chunk)} bytes")
            # Process audio data...
        else:
            print("Timeout, no data")
except KeyboardInterrupt:
    pass
finally:
    tap.close()

๐Ÿง Linux Example

from proctap import ProcessAudioCapture, StreamConfig
import wave

pid = 12345  # Your target process ID

# Create WAV file
wav = wave.open("linux_capture.wav", "wb")
wav.setnchannels(2)
wav.setsampwidth(2)
wav.setframerate(44100)

def on_data(pcm, frames):
    wav.writeframes(pcm)

# Create stream config (Linux backend respects these settings)
config = StreamConfig(sample_rate=44100, channels=2)

try:
    with ProcessAudioCapture(pid, config=config, on_data=on_data):
        print("โš ๏ธ  Make sure the process is actively playing audio!")
        input("Recording... Press Enter to stop.\n")
finally:
    wav.close()

Linux-specific requirements:

  • Install system package: sudo apt-get install pulseaudio-utils (provides parec command)
  • Python dependency pulsectl is automatically installed with pip install proc-tap
  • The target process must be actively playing audio
  • See examples/linux_basic.py for a complete example

๐ŸŽ macOS Example

from proctap import ProcessAudioCapture, StreamConfig
import wave

pid = 12345  # Your target process ID

# Create WAV file
wav = wave.open("macos_capture.wav", "wb")
wav.setnchannels(2)
wav.setsampwidth(2)
wav.setframerate(48000)  # macOS backend default is 48 kHz

def on_data(pcm, frames):
    wav.writeframes(pcm)

# Create stream config (macOS backend respects these settings)
config = StreamConfig(sample_rate=48000, channels=2)

try:
    with ProcessAudioCapture(pid, config=config, on_data=on_data):
        print("โš ๏ธ  Make sure the process is actively playing audio!")
        print("โš ๏ธ  On first run, macOS will prompt for permission.")
        input("Recording... Press Enter to stop.\n")
finally:
    wav.close()

macOS-specific requirements:

  • macOS 14.4 (Sonoma) or later
  • Swift CLI helper binary (proctap-macos) - automatically built during installation if Swift toolchain available
  • Audio capture permission - macOS will prompt on first run
  • The target process must be actively playing audio
  • See examples/macos_basic.py for a complete example

Building the Swift helper manually:

cd swift/proctap-macos
swift build -c release
cp .build/release/proctap-macos ../../src/proctap/bin/

๐Ÿ— Build From Source

git clone https://github.com/m96-chan/ProcTap
cd ProcTap
pip install -e .

Windows Build Requirements:

  • Visual Studio Build Tools
  • Windows SDK
  • CMake (if you modularize the C++ code)

Linux:

  • No C++ compiler required (pure Python)
  • System dependencies: pulseaudio-utils or pipewire with libpipewire-0.3-dev

macOS:

  • No C++ compiler required (pure Python)
  • Swift toolchain (optional, for building the Swift CLI helper)
  • If Swift is not available, pre-built binary is included in the package

๐Ÿค Contributing

Contributions are welcome! We have structured issue templates to help guide your contributions:

Special Interest:

  • PRs from WASAPI/C++ experts are especially appreciated
  • Linux backend improvements (PulseAudio/PipeWire per-app isolation)
  • macOS backend testing (Core Audio Process Tap on macOS 14.4+)
  • Cross-platform testing and compatibility
  • Performance profiling and optimization

๐Ÿ“„ License

MIT License

๐Ÿ‘ค Author

m96-chan
Windows Audio / VRChat Tools / Python / C++
https://github.com/m96-chan

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

proc_tap-0.3.1.tar.gz (64.4 kB view details)

Uploaded Source

Built Distributions

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

proc_tap-0.3.1-py3-none-any.whl (61.6 kB view details)

Uploaded Python 3

proc_tap-0.3.1-cp313-cp313-win_amd64.whl (80.8 kB view details)

Uploaded CPython 3.13Windows x86-64

proc_tap-0.3.1-cp312-cp312-win_amd64.whl (80.9 kB view details)

Uploaded CPython 3.12Windows x86-64

proc_tap-0.3.1-cp311-cp311-win_amd64.whl (80.8 kB view details)

Uploaded CPython 3.11Windows x86-64

proc_tap-0.3.1-cp310-cp310-win_amd64.whl (80.8 kB view details)

Uploaded CPython 3.10Windows x86-64

File details

Details for the file proc_tap-0.3.1.tar.gz.

File metadata

  • Download URL: proc_tap-0.3.1.tar.gz
  • Upload date:
  • Size: 64.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for proc_tap-0.3.1.tar.gz
Algorithm Hash digest
SHA256 89a78a13ca667461c89126083430b3c6b5e78075a3d0e9dd59fbe9d145cf2f10
MD5 93f348603c81cd24c34d6dd853462351
BLAKE2b-256 cfda0a971575472d8e135705b91206125af15160f643c085c215ff9e6e289ab6

See more details on using hashes here.

Provenance

The following attestation bundles were made for proc_tap-0.3.1.tar.gz:

Publisher: publish-pypi.yml on m96-chan/ProcTap

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

File details

Details for the file proc_tap-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: proc_tap-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 61.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for proc_tap-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0aa4e46ff701345b470ab4061a56cbcb826c87344255529838ad3f93cc85452b
MD5 d4f5afeb984b85066dd08bda516fce12
BLAKE2b-256 9e24538d491bfc8613f18ec57a26079846104b47b9c1ac7754dcd3c7c8fff15b

See more details on using hashes here.

Provenance

The following attestation bundles were made for proc_tap-0.3.1-py3-none-any.whl:

Publisher: publish-pypi.yml on m96-chan/ProcTap

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

File details

Details for the file proc_tap-0.3.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: proc_tap-0.3.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 80.8 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for proc_tap-0.3.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 97034e16e15ff7f4389a4a01ee7486fa01c52543399bd1cc60dbe29f497232f5
MD5 137b25bdc39df9e976fa342e44e081b6
BLAKE2b-256 07008628f0563f46b5547adab8cce60a19dafe2f66ee5fb11d8fcf6913599c68

See more details on using hashes here.

Provenance

The following attestation bundles were made for proc_tap-0.3.1-cp313-cp313-win_amd64.whl:

Publisher: publish-pypi.yml on m96-chan/ProcTap

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

File details

Details for the file proc_tap-0.3.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: proc_tap-0.3.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 80.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for proc_tap-0.3.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 88402d6ef90dfe8b2b8e01350487dc401e8317e367cd6fd7a0c926b9094faf88
MD5 ac09fd106acb4ac2634cb22be9939d93
BLAKE2b-256 d13d5fc3f9fe3c73f585446bfc292236d5bbee544fa0bf4026693d8dec459400

See more details on using hashes here.

Provenance

The following attestation bundles were made for proc_tap-0.3.1-cp312-cp312-win_amd64.whl:

Publisher: publish-pypi.yml on m96-chan/ProcTap

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

File details

Details for the file proc_tap-0.3.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: proc_tap-0.3.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 80.8 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for proc_tap-0.3.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 57436a18e3b90a967849a27bdbd64661c35dcc0fd3304b4d156892ddea9b179c
MD5 af13863cae6d6fb08507e1bc56a34d5d
BLAKE2b-256 c9430b1801e18e6d89f823199fb95bd4c9924b89530d3adb476284b300a51cf7

See more details on using hashes here.

Provenance

The following attestation bundles were made for proc_tap-0.3.1-cp311-cp311-win_amd64.whl:

Publisher: publish-pypi.yml on m96-chan/ProcTap

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

File details

Details for the file proc_tap-0.3.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: proc_tap-0.3.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 80.8 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for proc_tap-0.3.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4c8a34815779efd15c09bab3280fd0199f3a5d85348b19dffd52c1a4bc38827f
MD5 0d92558add3e428d12bf3ae159fe6fde
BLAKE2b-256 81ba2d3171d499348efa6e23659bec574f4e530c4ea9eb13b0af8c0180c7b25c

See more details on using hashes here.

Provenance

The following attestation bundles were made for proc_tap-0.3.1-cp310-cp310-win_amd64.whl:

Publisher: publish-pypi.yml on m96-chan/ProcTap

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