Skip to main content

streaming mp3 decoder

Project description

streamp3-313compat

This is a fork of streamp3, that converts the project over to a newer cython version, producing code compatible with python3.13.


streamp3

This library implements streaming MP3 decompression using the LAME library.

Status

PyPI CircleCI Coveralls

Installation

First, make sure you have the LAME libraries and headers installed.

macOS

brew install lame

Debian/Ubuntu

apt install libmp3lame-dev

Install with pip

pip install streamp3

Usage

To begin decoding an MP3, construct an MP3Decoder, passing it in a binary stream or bytes object. You can then access the bit_rate, sample_rate, and num_channels properties for information about the MP3.

from streamp3 import MP3Decoder

with open('my.mp3', 'rb') as mp3_file:
    decoder = MP3Decoder(mp3_file)
    print(decoder.bit_rate, decoder.sample_rate, decoder.num_channels)

You can then read samples from the stream directly using the read() method or use the decoder as an iterator. Samples are returned as bytes objects, which are 16-bit PCM encoded, with samples interleaved across channels. This example streams an MP3 file to the system speaker using PyAudio.

import pyaudio
from streamp3 import MP3Decoder

with open('my.mp3', 'rb') as mp3_file:
    decoder = MP3Decoder(mp3_file)

    audio = pyaudio.PyAudio()
    device = audio.get_default_output_device_info()
    speaker = audio.open(output=True,
                         input_device_index=device['index'],
                         format=pyaudio.paInt16,
                         channels=decoder.num_channels,
                         rate=decoder.sample_rate)

    for chunk in decoder:
        speaker.write(chunk)

Development

Setup

We generally use pyenv to create virtual environments. The following script creates a virtual environment for the project and installs dependencies.

pyenv install 3.6.4
pyenv virtualenv 3.6.4 streamp3
pip install -r requirements.txt

Deployment

The project uses setup.py for installation and is deployed to PyPI. The project can be built for installation with the following command:

python setup.py clean --all; rm -r ./dist
python setup.py sdist bdist_wheel

The wheel and source distribution can then be uploaded to PyPI using twine.

twine upload --repository-url=https://upload.pypi.org/legacy/ dist/*

License

Copyright 2018 Pylon, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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

streamp3_313compat-0.1.13.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamp3_313compat-0.1.13-cp313-cp313-macosx_15_0_arm64.whl (163.5 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

File details

Details for the file streamp3_313compat-0.1.13.tar.gz.

File metadata

  • Download URL: streamp3_313compat-0.1.13.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for streamp3_313compat-0.1.13.tar.gz
Algorithm Hash digest
SHA256 99d4d801d18fdbe98b0c0f846e840777ffe275d9c4ea79bb035027d9da06be11
MD5 5291e126e92f4f7a6b2dc9c796318ec8
BLAKE2b-256 6ca16332864b7e150315de714cf59274cc5f1eff153977e67bcf032c7e56a7fb

See more details on using hashes here.

File details

Details for the file streamp3_313compat-0.1.13-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for streamp3_313compat-0.1.13-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 682e1b3bccb9f6bb4ee75558da7aa7def1ec331c7b9849a355d457cc75c90dfc
MD5 6784fd0b7e5fb41260c800cc44041952
BLAKE2b-256 f1c90a735d3d94cf99439bdf635f2b20d8086a814c2f2dd98ecaa52004c6032d

See more details on using hashes here.

Supported by

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