Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/20tab/mpg123-python
mpg123 python wrapper
https://github.com/20tab/mpg123-python
Last synced: about 11 hours 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 (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-23T13:10:12.000Z (over 7 years ago)
- Last Synced: 2024-04-24T03:23:20.688Z (7 months ago)
- Language: Python
- Size: 6.04 MB
- Stars: 15
- Watchers: 4
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mpg123-python
mpg123 python wrapper using ctypesmpg123 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 wavemp3 = 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