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.2.0.tar.gz (1.1 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.2.0-cp311-cp311-win_amd64.whl (818.2 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

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

File metadata

  • Download URL: py_p_audio-0.2.0.tar.gz
  • Upload date:
  • Size: 1.1 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.2.0.tar.gz
Algorithm Hash digest
SHA256 8c6e383d391ddc5c843264b9ce885cb423367a084e843df86d9749bd5feeb1ee
MD5 f7a0d205ef74c346cb189966a3ca6124
BLAKE2b-256 f26da41fd80aa072944e735761875fc67f6b6c61dd52669de476aa4da1bba96e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_p_audio-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 818.2 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.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 eddca076679b132c82aceff046888876a7805c125a852134e321ba7fb9050e74
MD5 5610317d14a72c60450f822f6ec753c2
BLAKE2b-256 adb46f0ade23f22dc8dc224fe63cc47007f2b8fcb4b8565ba7605b2f9b881959

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