Git Product home page Git Product logo

mpg123-python's Introduction

mpg123-python

mpg123 python wrapper using ctypes

mpg123 libraries are available on the official site: https://www.mpg123.de/

CPython 2 and 3 are supported as well as PyPy

Quick intro

this is a simple mp3 player using the first available sound device as the output (libout123 is part of the mpg123 distribution)

from mpg123 import Mpg123, Out123

# load an mp3 file
mp3 = Mpg123('tests/bensound-scifi.mp3')

# use libout123 to access the sound device
out = Out123()

# decode mp3 frames and send them to the sound device
for frame in mp3.iter_frames(out.start):
    out.play(frame)

this is another example showing how to encode an mp3 to a wave file:

from mpg123 import Mpg123
import wave

mp3 = Mpg123('tests/bensound-epic.mp3')

# get informations about the file
rate, channels, encoding = mp3.get_format()

# prepare the wave header
wav = wave.open('bensound-epic.wav', 'wb')
wav.setnchannels(channels)
wav.setframerate(rate)
wav.setsampwidth(mp3.get_width_by_encoding(encoding))

# fill the wave file
for frame in mp3.iter_frames():
    wav.writeframes(frame)

wav.close()

more examples, included streaming of webradio are available here: https://github.com/20tab/mpg123-python/tree/master/examples

Test suite

The example files are "Royalty Free Music from Bensound" (http://www.bensound.com). For all of the test files a ID3v1 record has been added

mpg123-python's People

Contributors

unbit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mpg123-python's Issues

Cross-Platform Installation Issues

Hi, I am trying to figure out how to install the mpg123 libraries so that they work with your python package. I saw that you are using "find_libraries" to find mpg123, but I am looking for more details on what that actually does.

I would love to be able to specify the location of my mpg123 installation... For example, on Windows I have a single static mpg123.exe file. I'd prefer not to add it to the path, but rather point your program to this exe. Any tips to point me in the right direction?

My end goal is to play mp3 files (chunk by chunk) cross-platform with as few dependencies as possible. Cheers.

Windows10 lib123out issue

This simple code here

from mpg123 import Mpg123, Out123

# load an mp3 file
mp3 = Mpg123('D:/mpg123/test.mp3', library_path = 'D:/mpg123/libmpg123-0.dll')

# use libout123 to access the sound device
out = Out123(library_path = 'D:/mpg123/libout123-0.dll')

# decode mp3 frames and send them to the sound device
for frame in mp3.iter_frames(out.start):
    out.play(frame)

Gives this error:

C:\Data\Anaconda3\python.exe "C:/Users/$Username$/IdeaProjects/ESP_1/sound2.py"
Traceback (most recent call last):
  File "C:/Users/$Username$/IdeaProjects/ESP_1/sound2.py", line 7, in <module>
    out = Out123(library_path = 'D:/mpg123/libout123-0.dll')
  File "C:\Data\Anaconda3\lib\site-packages\mpg123.py", line 282, in __init__
    raise self.OpenException(self.plain_strerror(errcode))
mpg123.OpenException: invalid error code
[src/libout123/module.c:185] error: Failure getting module directory! (Perhaps set MPG123_MODDIR?)
[src/libout123/module.c:185] error: Failure getting module directory! (Perhaps set MPG123_MODDIR?)
[src/libout123/libout123.c:451] error: Found no driver out of [win32,win32_wasapi] working with device <default>.

How to get it working with windows.. I am thinking the drivers in mpg123/plugin are not getting loaded?

Question - Conversion

Do you know of a way I could do output the following transcode to a new wav.

-r 8000 --8bit -m

Using your wrapper, I would assume its something to do with Out123, I've looked at the mpg123 library API, but nothing really jumps out?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.