Skip to main content

Windows DLL for capturing audio from specific processes

Project description

ProcessAudioCapture

A Windows DLL for capturing audio from specific processes (applications).

License: MIT Windows

Overview

ProcessAudioCapture uses the AUDIOCLIENT_PROCESS_LOOPBACK_PARAMS API introduced in Windows 10 version 2004 (Build 19041) to capture audio output from a specific process only.

Unlike system-wide loopback capture (which records all audio), this library allows you to:

  • Record audio from a single application (e.g., browser, game, media player)
  • Exclude a specific application's audio from recording
  • Monitor real-time audio levels from a specific process

Based on Microsoft's official ApplicationLoopback sample.

Features

  • Process-specific capture - Record audio from only the specified process (INCLUDE mode)
  • Process exclusion - Record all audio except from the specified process (EXCLUDE mode)
  • Real-time level monitoring - Get audio level in dB via callback
  • Pause/Resume support - Pause and resume recording without stopping
  • WAV file output - Direct output to WAV file
  • Process enumeration - List all processes currently outputting audio
  • Python bindings included - Ready-to-use Python wrapper

Requirements

  • OS: Windows 10 version 2004 (Build 19041) or later, or Windows 11
  • Build Environment (if building from source):
    • Visual Studio 2019/2022 with C++ Desktop Development
    • Windows 10 SDK (10.0.19041.0 or later)
    • CMake 3.16 or later

Installation

Using Prebuilt Binaries

Download the latest release from the Releases page.

Extract and use:

  • ProcessAudioCapture.dll - The main DLL
  • python/process_audio_capture.py - Python wrapper

Building from Source

cd ProcessAudioCapture
mkdir build
cd build
cmake .. -G "Visual Studio 17 2022" -A x64
cmake --build . --config Release

Output files:

  • build/bin/Release/ProcessAudioCapture.dll
  • build/bin/Release/TestCapture.exe

Quick Start

Python

from process_audio_capture import ProcessAudioCapture

# Check if Windows version is supported
if not ProcessAudioCapture.is_supported():
    print("Windows 10 2004 or later required")
    exit()

# List processes outputting audio
processes = ProcessAudioCapture.enumerate_audio_processes()
for p in processes:
    print(f"PID: {p.pid}, Name: {p.name}, Window: {p.window_title}")

# Capture audio from a specific process
def on_level(level_db):
    print(f"Level: {level_db:.1f} dB")

with ProcessAudioCapture(
    pid=target_pid,
    output_path="output.wav",
    level_callback=on_level
) as capture:
    capture.start()
    time.sleep(10)  # Record for 10 seconds
    # capture.stop() is called automatically

C/C++

#include "ProcessAudioCapture.h"

// Check Windows version
if (!PacIsSupported()) {
    printf("Windows 10 2004 or later required\n");
    return;
}

// List audio processes
PacProcessInfo processes[64];
int count;
PacEnumerateAudioProcesses(processes, 64, &count);

// Start capture
PacHandle handle;
PacErrorCode err = PacStartCapture(
    targetPid,           // Target process ID
    PAC_MODE_INCLUDE,    // Capture mode
    L"output.wav",       // Output file (NULL for monitoring only)
    levelCallback,       // Level callback (can be NULL)
    nullptr,             // User data
    &handle
);

// During capture...
float levelDb;
PacGetLevel(handle, &levelDb);

// Pause/Resume
PacPauseCapture(handle);
// ... paused ...
PacResumeCapture(handle);

// Stop capture
PacStopCapture(handle);

API Reference

Functions

Function Description
PacIsSupported() Check if Windows version is supported
PacEnumerateAudioProcesses() Get list of processes outputting audio
PacStartCapture() Start capturing audio from a process
PacStopCapture() Stop capturing
PacPauseCapture() Pause capturing (audio data not written)
PacResumeCapture() Resume capturing
PacIsPaused() Check if capture is paused
PacGetLevel() Get current audio level in dB
PacIsCapturing() Check if currently capturing
PacGetLastErrorMessage() Get last error message
PacGetVersion() Get DLL version

Error Codes

Code Value Description
PAC_SUCCESS 0 Success
PAC_ERROR_INVALID_PARAM -1 Invalid parameter
PAC_ERROR_NOT_SUPPORTED -2 Windows version not supported
PAC_ERROR_PROCESS_NOT_FOUND -3 Process not found
PAC_ERROR_AUDIO_INIT_FAILED -4 Audio initialization failed
PAC_ERROR_FILE_CREATE_FAILED -5 File creation failed
PAC_ERROR_ALREADY_RECORDING -6 Already recording
PAC_ERROR_NOT_RECORDING -7 Not recording

Capture Modes

Mode Description
PAC_MODE_INCLUDE Capture only the specified process's audio
PAC_MODE_EXCLUDE Capture all audio except the specified process

Directory Structure

ProcessAudioCapture/
├── CMakeLists.txt          # Build configuration
├── LICENSE                 # MIT License
├── README.md               # This file
├── src/
│   ├── ProcessAudioCapture.h   # Public API header
│   ├── ProcessAudioCapture.cpp # DLL implementation
│   ├── LoopbackCapture.h       # Internal capture header
│   └── LoopbackCapture.cpp     # Internal capture implementation
├── python/
│   └── process_audio_capture.py  # Python wrapper
├── test/
│   └── test_capture.cpp    # C++ test application
├── prebuilt/               # Prebuilt binaries
│   └── x64/
│       └── ProcessAudioCapture.dll
└── build/                  # Build output (CMake generated)

Limitations

  1. DRM-protected content: Cannot capture (Windows restriction)
  2. Audio format: Fixed at 48kHz or device default, 32-bit float, stereo
  3. Child processes: Audio from child processes of the target is also included/excluded

Use Cases

  • Recording game audio without microphone
  • Capturing browser audio (meetings, videos, music)
  • Audio processing pipelines
  • Accessibility tools
  • Streaming/broadcasting specific application audio

License

MIT License - see LICENSE file.

Based on Microsoft's ApplicationLoopback sample.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

  • Microsoft for the ApplicationLoopback sample code
  • Windows Audio Session API (WASAPI) documentation

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

process_audio_capture-1.0.0.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

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

process_audio_capture-1.0.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file process_audio_capture-1.0.0.tar.gz.

File metadata

  • Download URL: process_audio_capture-1.0.0.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for process_audio_capture-1.0.0.tar.gz
Algorithm Hash digest
SHA256 311c45bd9de57bd3f749669cb88b4a47c5c775cfe6d29484e34317fc002ef22f
MD5 bd22d6b9ed1ad7360c9c4afb55ce1a26
BLAKE2b-256 eb0be472720cf338708e0b381b35a4fde4bd3f6b4e59f9472c51cf099217c516

See more details on using hashes here.

File details

Details for the file process_audio_capture-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for process_audio_capture-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7654f26fb54f8dab47fa92f50d31b7c4c68cfac9cb7aceafb3cc6637fb2d1595
MD5 56880515fad9952ca2ae826e3b27aa7b
BLAKE2b-256 1fc0cdd16212c799cb79778ab3ee591a29aa10ea98cc89e4435bb6fbf2cb47f3

See more details on using hashes here.

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