Skip to main content

streamp3

This library implements streaming MP3 decompression using the LAME library.

Status

PyPI CircleCI Coveralls

Installation

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

LAME must also be installed. This can be done on OSX via homebrew.

brew install lame

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamp3-0.1.6.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

streamp3-0.1.6-cp36-cp36m-macosx_10_13_x86_64.whl (22.0 kB view details)

Uploaded CPython 3.6mmacOS 10.13+ x86-64

File details

Details for the file streamp3-0.1.6.tar.gz.

File metadata

  • Download URL: streamp3-0.1.6.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for streamp3-0.1.6.tar.gz
Algorithm Hash digest
SHA256 61fbb78971c6b8b9835fd4b45373452b7742e2d09395baad798dd590116bc7b0
MD5 4cb7a9826c7b4d5a1fad639eb830c670
BLAKE2b-256 c4006030c571ccddd2bc4883f0ebb352c9deb98097a95f118d429f6b6031958c

See more details on using hashes here.

File details

Details for the file streamp3-0.1.6-cp36-cp36m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: streamp3-0.1.6-cp36-cp36m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: CPython 3.6m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for streamp3-0.1.6-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 73af67b3d6189af57585ec12eceb4b971dbc685f408fe3b77b812b93e0aa87b5
MD5 904b97dd9ae4108a19a9ad6cec16c2a1
BLAKE2b-256 c6e83e28b6f6990abe2786875d1cb457bc2a9201028a0e46f022b9a7ae40c50b

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

This release

0.1.6 This release

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page