Audio Seek
A lightweight Python library for reading arbitrary time slices out of common audio files without loading them fully — with minimal dependencies (numpy + soundfile).
Key Features
- Zero Waste: Reads and decodes only the requested time slice, not the whole file.
- Usual Formats: Supports WAV, AIFF, FLAC, OGG/Vorbis, and MP3 via
soundfile/libsndfile. - O(1) Where Possible: Seeking into uncompressed PCM (WAV/AIFF) is a direct sample-offset seek, O(1). Compressed formats (MP3/FLAC/OGG) are frame/entropy coded, so seeking there is best-effort at frame granularity, not sample-exact.
- Complexity Introspection:
AudioSeek.seek_complexity()tells you which regime a given file falls into. - Minimal Dependencies: Just
numpyandsoundfile— no bundled codecs, no JIT toolchains.
Installation
pip install audio-seek
Quick Start
Read a Specific Audio Segment
from audio_seek import read_audio_segment
# Read 5 seconds starting at 2 minutes
segment = read_audio_segment(
file_path="long_audio.wav",
start_sec=120.0,
duration_sec=5.0,
)
# Returns a numpy float32 array of shape (sample_rate * duration_sec,)
Get Duration Without Loading Audio
from audio_seek import AudioSeek
# Only reads the header, doesn't decode audio data
duration = AudioSeek.get_duration("audio.mp3")
print(f"Duration: {duration:.2f}s")
Check Seek Complexity
from audio_seek import AudioSeek
AudioSeek.seek_complexity("audio.wav") # "O(1)" — uncompressed PCM
AudioSeek.seek_complexity("audio.mp3") # "O(n)" — frame/entropy coded
Extract a Segment to a New WAV File
from audio_seek import AudioSeek
AudioSeek.read_segment_to_file(
file_path="input.mp3",
start_sec=10.0,
duration_sec=15.0,
output_path="clip.wav", # written as PCM_16 WAV
)
Mix Multi-Channel Audio Down to Mono
from audio_seek import ensure_mono
mono = ensure_mono(stereo_data, style="soundfile") # (samples, channels) -> (samples,)
How It Works
audio-seek wraps soundfile/libsndfile and seeks directly via SoundFile.seek():
- For uncompressed PCM (WAV, AIFF), each sample occupies a fixed number of bytes, so seeking is a direct file-offset computation — true O(1), sample-accurate.
- For compressed formats (MP3, FLAC, OGG/Vorbis), audio is encoded in frames/blocks of varying or fixed sample counts, sometimes with decoder warm-up requirements. Seeking there lands on the nearest frame boundary and is not guaranteed sample-exact — closer to O(n) in the worst case.
Use Cases
Ideal for applications requiring low-latency access to specific segments of long audio recordings:
- Machine Learning: Dataset slicing without loading entire files
- Web Services: Real-time audio segment delivery
- Audio Processing: Random access pipelines
Requirements
- Python >= 3.11
- numpy
- soundfile
Testing
pytest tests/ -v
License
Apache License 2.0 - see LICENSE file for details.
Metadata
Release files for audio-seek 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| audio_seek-0.2.0.tar.gz | 9.4 kB | Without provenance | Details for audio_seek-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| audio_seek-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for audio_seek-0.2.0-py3-none-any.whl |
Total release size: 20.8 kB
Release files / audio_seek-0.2.0.tar.gz
| Download URL | audio_seek-0.2.0.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04c716c05e84e246915fd669c09864a3019bde3f014e5c4acee715293eac5f34
|
|
BLAKE2b-256 checksum How to use checksums |
fc8344bbad005513cbc85f1876b9c38aff74d60cd0fc62ab1ea8fd76c805b655
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.11.15 Darwin/25.3.0
|
Release files / audio_seek-0.2.0-py3-none-any.whl
| Download URL | audio_seek-0.2.0-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
10ac0b407203b27d91f9b07067c942daf1b69cdffd3b3a819b6a7b94ba257f84
|
|
BLAKE2b-256 checksum How to use checksums |
ea5d4a4b71fed3e378376da93e4f9061571acccdf5028456ce3bcbbff022f9c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.11.15 Darwin/25.3.0
|
Security for audio-seek 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.