Search code examples
pythonpython-3.xogg

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)?


Solution

  • 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