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 โœ… Officially Supported ScreenCaptureKit macOS 13+ (Ventura), bundleID-based (v0.4.0+)

* Linux is fully supported with PipeWire/PulseAudio (v0.3.0+). macOS is officially supported with ScreenCaptureKit (v0.4.0+).


๐Ÿš€ 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 (officially supported, v0.4.0+)

  • โšก Platform-optimized backends โ†’ Windows: ActivateAudioInterfaceAsync (modern WASAPI) โ†’ Linux: PipeWire Native API / PulseAudio (fully supported, v0.3.0+) โ†’ macOS: ScreenCaptureKit API (macOS 13+, bundleID-based, v0.4.0+)

  • ๐Ÿงต Low-latency, thread-safe audio engine โ†’ 48 kHz / stereo / float32 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

# Native float32 output (no conversion)
proctap --pid 12345 --format float32 --stdout | ffmpeg -f f32le -ar 48000 -ac 2 -i pipe:0 output.mp3

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)
--format {int16,float32} Output format: int16 or float32 (default: int16)
--verbose Enable verbose logging to stderr
--list-audio-procs List all processes currently playing audio

Finding Process IDs:

# Windows
tasklist | findstr "VRChat"

# Linux/macOS
ps aux | grep VRChat

FFmpeg Format Arguments:

The CLI outputs raw PCM at 48kHz stereo. FFmpeg needs these arguments based on --format:

int16 (default):

  • -f s16le: Signed 16-bit little-endian PCM
  • -ar 48000: Sample rate (48kHz, fixed)
  • -ac 2: Channels (stereo, fixed)
  • -i pipe:0: Read from stdin

float32:

  • -f f32le: 32-bit float little-endian PCM
  • -ar 48000: Sample rate (48kHz, fixed)
  • -ac 2: Channels (stereo, fixed)
  • -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 (Officially Supported - v0.4.0+):

  • macOS 13.0 (Ventura) or later (macOS 13+ recommended)
  • Python 3.10+
  • Swift helper binary (screencapture-audio)
  • Screen Recording permission (automatically prompted)
  • โœ… ScreenCaptureKit Backend: Apple Silicon compatible, no AMFI/SIP hacks needed
  • โœ… Simple Permissions: Screen Recording only (no Microphone/TCC hacks)
  • โœ… Low Latency: ~10-15ms audio capture

๐Ÿงฐ 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

Windows Backend Format (WASAPI, returned to Python):

Parameter Value Description
Sample Rate 48,000 Hz Professional audio quality
Channels 2 Stereo
Format float32 IEEE 754 floating point (-1.0 to +1.0)
Fallback 44.1kHz int16 Auto-converted to 48kHz float32 if float32 init fails

Important Note: For WAV file output, you must convert float32 to int16:

import numpy as np

def on_data(pcm: bytes, frames: int):
    # Convert float32 to int16 for WAV files
    float_samples = np.frombuffer(pcm, dtype=np.float32)
    int16_samples = (np.clip(float_samples, -1.0, 1.0) * 32767).astype(np.int16)
    wav.writeframes(int16_samples.tobytes())

๐ŸŽฏ 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

๐ŸŽจ Advanced Features (Contrib)

ProcTap includes optional contrib modules for advanced audio processing:

๐Ÿ“Š Real-Time Audio Analysis & Visualization

Monitor and analyze audio from processes in real-time with spectrum analysis, volume meters, and frequency visualization.

CLI Mode (Terminal-based):

# Analyze by process ID
python -m proctap.contrib.analysis --pid 12345

# Analyze by process name
python -m proctap.contrib.analysis --name "VRChat.exe"

GUI Mode (Matplotlib window):

# Launch GUI visualizer
python -m proctap.contrib.analysis --pid 12345 --gui

# Adjust FFT size for better frequency resolution
python -m proctap.contrib.analysis --pid 12345 --gui --fft-size 4096

Features:

  • ๐Ÿ“ˆ Real-time spectrum analyzer (FFT-based frequency analysis)
  • ๐Ÿ”Š Volume meters (RMS and peak levels in dB)
  • ๐ŸŽต Frequency band analysis (Sub, Bass, Mid, Treble, Presence, Brilliance)
  • ๐Ÿ’ป Terminal visualization (CLI mode) or ๐Ÿ“Š Matplotlib plots (GUI mode)
  • โš™๏ธ Configurable FFT size (512, 1024, 2048, 4096, 8192)

Programmatic Usage:

from proctap import ProcessAudioCapture
from proctap.contrib import AudioAnalyzer, CLIVisualizer

# Create analyzer
analyzer = AudioAnalyzer(sample_rate=48000, fft_size=2048)

# Create callback for audio processing
def on_audio(pcm: bytes, frames: int):
    analyzer.process_audio(pcm)

# Start audio capture with callback
tap = ProcessAudioCapture(pid=12345, on_data=on_audio)
tap.start()

# Create and run visualizer
visualizer = CLIVisualizer(analyzer)
visualizer.start()  # Blocking - displays in terminal

Optional Dependencies:

  • CLI mode: Included (uses numpy/scipy)
  • GUI mode: Requires matplotlib (pip install matplotlib)

๐Ÿ“š 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 (v0.4.0+)

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 Screen Recording permission.")
        input("Recording... Press Enter to stop.\n")
finally:
    wav.close()

macOS-specific requirements (v0.4.0+):

  • macOS 13.0 (Ventura) or later
  • Swift helper binary (screencapture-audio) - automatically built during installation
  • Screen Recording permission - macOS will prompt on first run
  • The target process must be actively playing audio
  • Works with bundleID-based capture (PID is automatically converted to bundleID)
  • See examples/macos_screencapture_test.py for a complete example

Building the Swift helper manually:

cd src/proctap/swift/screencapture-audio
swift build -c release

Note: The ScreenCaptureKit backend (v0.4.0+) is recommended over the experimental PyObjC/C extension backends.


๐Ÿ— 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:

  • Swift toolchain required for building the ScreenCaptureKit helper (v0.4.0+)
  • Xcode Command Line Tools: xcode-select --install
  • No C++ compiler required (pure Python backend)
  • Helper binary location: src/proctap/swift/screencapture-audio/

๐Ÿค 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 (ScreenCaptureKit on macOS 13+)
  • 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-1.0.3.tar.gz (105.9 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-1.0.3-py3-none-any.whl (85.3 kB view details)

Uploaded Python 3

proc_tap-1.0.3-cp313-cp313-win_amd64.whl (106.0 kB view details)

Uploaded CPython 3.13Windows x86-64

proc_tap-1.0.3-cp312-cp312-win_amd64.whl (106.0 kB view details)

Uploaded CPython 3.12Windows x86-64

proc_tap-1.0.3-cp311-cp311-win_amd64.whl (106.0 kB view details)

Uploaded CPython 3.11Windows x86-64

proc_tap-1.0.3-cp310-cp310-win_amd64.whl (106.0 kB view details)

Uploaded CPython 3.10Windows x86-64

File details

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

File metadata

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

File hashes

Hashes for proc_tap-1.0.3.tar.gz
Algorithm Hash digest
SHA256 f6b2c1bcd1cfca2428e6ee26493200c7d79d7ce7ffa442174a09f2787e20dd89
MD5 45d235ce7147d31084c1d8e31a67df89
BLAKE2b-256 aa67b620f134a9609e16a9344e58f820a92efbb83a2609324bd2f1ed3b99faa5

See more details on using hashes here.

Provenance

The following attestation bundles were made for proc_tap-1.0.3.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-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: proc_tap-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 85.3 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-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5e8b02863f787a992377b2c0c5e1f3680fac92d608caa79fed3a0de0bb58b72e
MD5 73eea93a274fbb581de47caa68bba9d2
BLAKE2b-256 0d74c6887c5e4955d4f17a4f649b7b2c310351094d6d25e2a241815d622f84a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for proc_tap-1.0.3-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-1.0.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: proc_tap-1.0.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 106.0 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-1.0.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 88c6246147fc437ca7b59d9042b71881939cd194042bda3a038228ce4979ee39
MD5 c0fdc3fab5414f2142832d4f0f18d62f
BLAKE2b-256 23d5210cb5c95c2250adddf8a0c79fb2b759e4c84b7e36cd16417c050e2201f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for proc_tap-1.0.3-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-1.0.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: proc_tap-1.0.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 106.0 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-1.0.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 48ddc19b36db2ee67d78eabe5a49a7f5e445de71011d870e3dd7be064d2f474f
MD5 9ba9adb1db830e5e1e22ddb4c886cd0e
BLAKE2b-256 f62c165217a8df09088adc974495ca9e316ebe19f1d8f600197cfd13ad95c9a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for proc_tap-1.0.3-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-1.0.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: proc_tap-1.0.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 106.0 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-1.0.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6fa25b9eedd5f619709973ac5b9e25d7d581ae3bf68b134919f3549fd1eb8f29
MD5 7a66a91ccffd3de88dfd3a94a6818350
BLAKE2b-256 09b9547c639362ad2afc3505ec05c74653af57b6b2c95b12c4de09244e7ac142

See more details on using hashes here.

Provenance

The following attestation bundles were made for proc_tap-1.0.3-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-1.0.3-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: proc_tap-1.0.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 106.0 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-1.0.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6232e970eb1a21320a59c02430daf1e164663f493022ae3b7a329894ba12693e
MD5 eba5b6c42c5330494bf330892c315086
BLAKE2b-256 73c8c48d850a4f106f4615ce172d43f452e05ed64029f825a34e6c5ca7ef189e

See more details on using hashes here.

Provenance

The following attestation bundles were made for proc_tap-1.0.3-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