Skip to main content

Fast library to load MP3 into NumPY arrays

Project description


A fast python library to load mp3 data into NumPy arrays.

It is based on lieff's minimp3


pip install np3


import np3

mp3 = np3.MP3(path="/my/mp3/file")

# or

with open("/path/to/file.mp3") as mp3_fh:
    mp3 = np3.MP3(file=mp3_fh)

# or

data: bytes = obtain_mp3_data()
mp3 = np3.MP3(data=data)

print(f"Channels: {mp3.channels}")
print(f"Sampling rate: {mp3.hz} Hz")

length = len(mp3.samples[0]) / mp3.hz
print(f"Length: {length:.1f} seconds")

Threaded performance

GIL is released before decoding starts. On multi core machines this brings additional performance when decoding in separate threads. While decoding a single file does not parallelise, other python threads can continue working while the file is being processed. Where multiple files need decoding this performance gain becomes particularly significant.

from concurrent.futures import ThreadPoolExecutor

files = ["/path/to/file1.mp3", "/path/to/file2.mp3", ...]

with ThreadPoolExecutor() as executor:
    mp3s =
        lambda p: np3.MP3(path=p),

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

np3-0.2.tar.gz (34.9 kB view hashes)

Uploaded source

Built Distributions

np3-0.2-cp311-cp311-musllinux_1_1_x86_64.whl (111.4 kB view hashes)

Uploaded cp311

np3-0.2-cp311-cp311-musllinux_1_1_i686.whl (97.8 kB view hashes)

Uploaded cp311

np3-0.2-cp310-cp310-musllinux_1_1_i686.whl (96.9 kB view hashes)

Uploaded cp310

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page