https://github.com/20tab/mpg123-python
mpg123 python wrapper
https://github.com/20tab/mpg123-python
Last synced: about 1 year ago
JSON representation
mpg123 python wrapper
- Host: GitHub
- URL: https://github.com/20tab/mpg123-python
- Owner: 20tab
- License: mit
- Created: 2017-07-23T06:53:21.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-23T13:10:12.000Z (almost 9 years ago)
- Last Synced: 2025-04-10T13:18:37.977Z (about 1 year ago)
- Language: Python
- Size: 6.04 MB
- Stars: 16
- Watchers: 3
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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)
```python
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:
```python
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