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.
Note
- Package name on PyPI:
py-p-audio- Import name in Python:
paudio
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 saveddevice_index: (Optional) Specific device index to record from. -1 for default devicechannels: (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 filestart(): Start playbackstop(): Stop playbackis_playing() -> bool: Check if currently playingcurrent_time() -> float: Get current playback position in secondstotal_time() -> float: Get total duration in secondsformat_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 devicesetup(output_path: str, device_index: int, channels: tuple) -> bool: Setup with specific device and channelsstart(): Start recordingstop(): Stop recordingis_recording() -> bool: Check if currently recordingcurrent_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.2.1
- Ensure the extension module installs to site-packages root for
import paudio - Wheel includes statically linked PortAudio (WASAPI/ASIO enabled)
- Verified non-blocking
Player/RecorderAPIs
0.2.0
- Internal build system refactor (CMake + scikit-build-core)
- PortAudio is fetched and built in wheel builds
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_p_audio-0.2.2.tar.gz.
File metadata
- Download URL: py_p_audio-0.2.2.tar.gz
- Upload date:
- Size: 4.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24082e43104d3c68fdbe50e39f35bdcd86d21c19d9eafbe4d24fcfa747de1bef
|
|
| MD5 |
68a9bafe71adb692d9d69cd7ab30e3af
|
|
| BLAKE2b-256 |
473d3c501b6a5b8a95f734fe9552c1b6b45bb534c5d05ed150f43eb2e5eaca40
|
File details
Details for the file py_p_audio-0.2.2-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: py_p_audio-0.2.2-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 555.6 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86749736badf4fac9274812e49b6a00a955bcde95ef3cd752e935e01b6b73d4b
|
|
| MD5 |
1558e0ed44011a97327cae1b730ca2ef
|
|
| BLAKE2b-256 |
f1600b65b4bc0fabb44828da6a9f6713e546d7c40e30746fc7b50771f4d68779
|