Skip to main content

Fast library to load MP3 into NumPY arrays

Project description

NP3

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

It is based on lieff's minimp3

Installation

pip install np3

Usage

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 = executor.map(
        lambda p: np3.MP3(path=p),
        files,
    )

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 CPython 3.11 musllinux: musl 1.1+ x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

np3-0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (108.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

np3-0.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (137.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

np3-0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (86.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

np3-0.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (136.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

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