Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you play ogg files in Python in Linux?

Could someone provide a short code or pseudocode example of how to play ogg files in Python 2.7.1 or Python 3.1.3 in Linux (along with a list of any dependencies from the Synaptic Package Manager, or elsewhere)?

like image 287
Winston C. Yang Avatar asked Feb 22 '26 11:02

Winston C. Yang


2 Answers

If you don't mind depending on numpy, my package audiolab works pretty well and supports oggfile out of the box as long as libsndfile itself supports it (it should on linux if you version is recent enough):

# the dependencies
sudo apt-get install libsndfile-dev python-numpy cython python-setuptools
# install audiolab
cd audiolab-0.11 && python setup.py install --user

The basic API is straightforward:

from scikits.audiolab.pysndfile.matapi import oggread
data, fs, enc = oggread("myfile.ogg")

A more complete API for controlling output dtype, range, etc... is also available. You can found releases on pypi, and the code on github

like image 82
David Cournapeau Avatar answered Feb 24 '26 02:02

David Cournapeau


Sometime ago I tried to write some game prototype in python and i used pygame. http://www.pygame.org/news.html You should be able to find it in synaptic, and it should install all needed dependencies, if ogg would not work you would probably need libvorbis, but you most likely have it installed already. Anyway, probably best thing to do is to read pygame. Otho if it's not a game that your making you might need another library. But then all I can suggest is try searching.

like image 21
morphles Avatar answered Feb 24 '26 02:02

morphles



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!