AudioLab
Project Links
Meta
Author: Zhendong Peng
Requires Python: >=3.8
Classifiers
Programming Language
- Python :: 3
Operating System
- OS Independent
audiolab
A Python library for audio processing built on top of soundfile, and PyAV (bindings for FFmpeg). audiolab provides a simple and efficient interface for loading, processing, and saving audio files.
Features
- Load audio from multiple sources: local paths, HTTP URLs, bytes, and BytesIO streams
- Load audio files in various formats (WAV, MP3, FLAC, AAC, etc.)
- Save audio files in different container formats
- Support for audio streaming and real-time processing (resampling, speeding up, and other filters)
- Command-line interface for audio file inspection
- Support for audio transformations and filtering
Installation
pip install audiolab
Quick Start
Load an audio file
from audiolab import load_audio
# Load audio from 7 to 30 seconds (duration: 23s) and convert to 16kHz mono
audio, rate = load_audio("audio.wav", offset=7, duration=23, rate=16000, to_mono=True)
print(f"Sample rate: {rate} Hz")
print(f"Audio shape: {audio.shape}")
Save an audio file
import numpy as np
from audiolab import save_audio
# Create a simple sine wave
rate = 44100
duration = 5
t = np.linspace(0, duration, rate * duration)
audio = np.sin(2 * np.pi * 440 * t)
# Save as WAV file
save_audio("tone.wav", audio, rate)
Get audio file information
from audiolab import info
# Get information about an audio file
print(info("audio.wav"))
Command-line usage
# Get information about an audio file
audi audio.wav
# Show only specific information
audi -r -c audio.wav # Show sample rate and channels only
audi -d audio.wav # Show duration in hours, minutes and seconds
audi -D audio.wav # Show duration in seconds
# Get audio information from URL
audi https://modelscope.cn/datasets/pengzhendong/filesamples/resolve/master/audio/m4a/sample1.m4a
Input File : 'https://modelscope.cn/datasets/pengzhendong/filesamples/resolve/master/audio/m4a/sample1.m4a' (mov,mp4,m4a,3gp,3g2,mj2)
Channels : 2
Sample Rate : 44100
Precision : 32-bit
Duration : 00:02:02.093 = 5384301 samples ~ 9156.97 CDDA sectors
File Size : 2 MB
Bit Rate : 131.8 kbps
Sample Encoding: AAC (Advanced Audio Coding)
Comments :
major_brand: M4A
minor_version: 512
compatible_brands: isomiso2
encoder: Lavf57.83.100
language: und
handler_name: SoundHandler
vendor_id: [0][0][0][0]
CLI Options
-f, --forced-decodingForced decoding the audio file to get the duration-t, --show-file-typeShow detected file-type-r, --show-sample-rateShow sample-rate-c, --show-channelsShow number of channels-s, --show-samplesShow number of samples (N/A if unavailable)-d, --show-duration-hmsShow duration in hours, minutes and seconds (N/A if unavailable)-D, --show-duration-secondsShow duration in seconds (N/A if unavailable)-b, --show-bits-per-sampleShow number of bits per sample (N/A if not applicable)-B, --show-bitrateShow the bitrate averaged over the whole file (N/A if unavailable)-p, --show-precisionShow estimated sample precision in bits-e, --show-encodingShow the name of the audio encoding-a, --show-commentsShow file comments (annotations) if available--helpShow this message and exit
If no specific options are selected, all information will be displayed by default.
API Overview
Core Functions
load_audio(): Load audio from filesave_audio(): Save audio to fileinfo(): Get information about an audio fileencode(): Transform audio to PCM bytestring
Classes
Reader: Read audio files with advanced optionsStreamReader: Read audio streamsWriter: Write audio files with custom parameters
Advanced Usage
Apply filters during loading
from audiolab import info, load_audio
from audiolab.av.filter import aresample, asetrate, atempo
# Speed perturbation
filters = [atempo(1.5)]
audio, rate = load_audio("audio.wav", filters=filters)
# Pitch perturbation
ratio = 1.5
rate = info("audio.wav").rate
filters = [asetrate(rate * ratio), atempo(1 / ratio), aresample(rate)]
audio, rate = load_audio("audio.wav", filters=filters)
Streaming processing
import numpy as np
from audiolab.av.filter import atempo
from audiolab import AudioPipe, Reader, save_audio
frames = []
reader = Reader("audio.wav")
pipe = AudioPipe(in_rate=reader.rate, filters=[atempo(2)])
for frame, _ in reader:
pipe.push(frame)
for frame, _ in pipe.pull():
frames.append(frame)
for frame, _ in pipe.pull(True):
frames.append(frame)
save_audio("output.wav", np.concatenate(frames, axis=1), reader.rate)
License
0.5.1
Mar 25, 2026
0.5.0
Mar 16, 2026
0.4.9
Mar 13, 2026
0.4.8
Jan 15, 2026
0.4.7
Dec 19, 2025
0.4.6
Dec 17, 2025
0.4.5
Dec 08, 2025
0.3.8
Nov 25, 2025
0.3.7
Nov 25, 2025
0.3.6
Sep 15, 2025
0.3.5
Sep 03, 2025
0.3.4
Aug 26, 2025
0.3.3
Aug 22, 2025
0.3.2
Aug 14, 2025
0.3.1
Jul 27, 2025
0.3.0
Jul 10, 2025
0.2.9
Jul 09, 2025
0.2.8
Apr 28, 2025
0.2.7
Apr 25, 2025
0.2.6
Apr 24, 2025
0.2.5
Apr 24, 2025
0.2.4
Apr 24, 2025
0.2.3
Apr 24, 2025
0.2.2
Apr 24, 2025
0.2.1
Apr 23, 2025
0.2.0
Apr 21, 2025
0.1.9
Apr 21, 2025
0.1.8
Apr 21, 2025
0.1.7
Apr 21, 2025
0.1.6
Apr 14, 2025
0.1.5
Apr 12, 2025
0.1.3
Apr 12, 2025
0.1.2
Apr 12, 2025
0.1.1
Apr 12, 2025
0.1.0
Apr 12, 2025
0.0.9
Apr 10, 2025
0.0.8
Apr 09, 2025