Skip to main content

High-performance cross-platform audio library with recording, playback, and loopback capture

Project description

py-p-audio (paudio)

A cross-platform audio library for Python with playback, recording, and device management capabilities. Built with C++ and PortAudio, providing high-performance audio I/O with ASIO/WASAPI support on Windows.

Installation

pip install py-p-audio

No additional dependencies required. All necessary libraries are bundled in the wheel package.

Features

  • Cross-platform audio playback and recording
  • WASAPI Loopback recording support (Windows)
  • ASIO support (Windows, when ASIO SDK available)
  • Simple Python API with both synchronous and asynchronous operations
  • Device enumeration and selection
  • No external dependencies - everything is statically linked

Quick Start

import paudio

# List all audio devices
paudio.list_devices()

# Play an audio file (blocking)
paudio.play("audio.wav")

# Record audio (blocking, press Ctrl+C to stop)
paudio.record("output.wav")

# Advanced: Record from specific device with specific channels
paudio.record("output.wav", device_index=1, channels=(0, 1))

API Reference

Module Functions

paudio.list_devices()

List all available audio devices including input, output, and loopback devices.

paudio.play(file_path: str)

Play an audio file. Blocks until playback is complete.

  • file_path: Path to the audio file to play

paudio.record(output_path: str, device_index: int = -1, channels: tuple = (-1, -1))

Record audio to a file. Blocks until recording is stopped (Ctrl+C).

  • output_path: Path where the recorded audio will be saved
  • device_index: (Optional) Specific device index to record from. -1 for default device
  • channels: (Optional) Tuple of (start_channel, end_channel) for multi-channel recording

Classes

paudio.Player

Non-blocking audio player for advanced playback control.

Methods:
  • load(file_path: str) -> bool: Load an audio file
  • start(): Start playback
  • stop(): Stop playback
  • is_playing() -> bool: Check if currently playing
  • current_time() -> float: Get current playback position in seconds
  • total_time() -> float: Get total duration in seconds
  • format_time(seconds: float) -> str: Format seconds to MM:SS string
Example:
import paudio
import time

player = paudio.Player()
player.load("music.wav")
player.start()

while player.is_playing():
    print(f"Playing: {player.format_time(player.current_time())} / {player.format_time(player.total_time())}")
    time.sleep(1)

paudio.Recorder

Non-blocking audio recorder for advanced recording control.

Methods:
  • setup(output_path: str) -> bool: Setup recording with default device
  • setup(output_path: str, device_index: int, channels: tuple) -> bool: Setup with specific device and channels
  • start(): Start recording
  • stop(): Stop recording
  • is_recording() -> bool: Check if currently recording
  • current_time() -> float: Get current recording duration in seconds
Example:
import paudio
import time

recorder = paudio.Recorder()
recorder.setup("recording.wav")
recorder.start()

# Record for 10 seconds
time.sleep(10)

recorder.stop()
print(f"Recorded {recorder.current_time()} seconds")

Device Selection

To record from a specific device, first list all devices to find the device index:

import paudio

# This will print all devices with their indices
paudio.list_devices()

# Example output:
# 1,W,I,Microphone Array (Intel SST),2
# 2,W,O,Speakers (SoundWire Audio) (WASAPI-Loopback),2,LOOPBACK
# ...

# Record from device index 2 (loopback recording)
paudio.record("system_audio.wav", device_index=2)

WASAPI Loopback Recording (Windows)

Record system audio output (what you hear from speakers):

import paudio

# List devices to find loopback devices (marked with LOOPBACK)
paudio.list_devices()

# Record system audio
recorder = paudio.Recorder()
recorder.setup("system_output.wav", device_index=2, channels=(0, 1))  # Stereo recording
recorder.start()
# ... recording ...
recorder.stop()

Building from Source

If you need to build from source:

git clone https://github.com/yourusername/py-p-audio.git
cd py-p-audio
pip install .

Requirements for building:

  • CMake 3.15+
  • C++17 compatible compiler
  • Python 3.8+

License

MIT License

Changelog

0.1.5

  • Fixed MinGW runtime DLL dependencies
  • All dependencies are now statically linked
  • No external DLL requirements for end users

0.1.4

  • Initial release
  • Basic playback and recording functionality
  • WASAPI loopback support

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

py_p_audio-0.1.5.tar.gz (23.4 MB view details)

Uploaded Source

Built Distribution

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

py_p_audio-0.1.5-cp311-cp311-win_amd64.whl (775.4 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

Details for the file py_p_audio-0.1.5.tar.gz.

File metadata

  • Download URL: py_p_audio-0.1.5.tar.gz
  • Upload date:
  • Size: 23.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for py_p_audio-0.1.5.tar.gz
Algorithm Hash digest
SHA256 cba3dfe466f70d2299ddd4b024d32494923ac32e094970bdd0122d5cf80830ad
MD5 138159596516baac29f65f12a9ffaa82
BLAKE2b-256 0c432462f2bb8d5995b56b6128ab4afbb77bc19361535091ece8319679568f36

See more details on using hashes here.

File details

Details for the file py_p_audio-0.1.5-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: py_p_audio-0.1.5-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 775.4 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for py_p_audio-0.1.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e9fb89bf31684bd30853d1292278e05e15f48004496e75c1bc79e01fccfdecb2
MD5 2a6957ae55741e967956c54437087ef0
BLAKE2b-256 8e22261c74a92b986aa03458ffb1a2db037b11b29fe1321868b537f4070dc1a0

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