Question

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

Was it helpful?

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

OTHER TIPS

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.

I used py-gstreamer to play ogg files with following code

import sys, os

##FOR UBUNTU 13.04 onwards
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst, Gtk
##end
GObject.threads_init()
Gst.init(None)

uri = "http://blender-podcast.org/episodes/Blender_Podcast_Episode_028.ogg"
#pipeline = Gst.Pipeline()
#delay = Gst.ElementFactory.make("audiodelay","delay")
player = Gst.ElementFactory.make("playbin", "player")
fakesink = Gst.ElementFactory.make("fakesink", "fakesink")
# pipeline.add(player)
# pipeline.add(fakesink)

player.set_property('uri', uri)
player.set_property("video-sink", fakesink)
player.set_state(Gst.State.PLAYING)
Gtk.main()

Installation

sudo apt-get install libgstreamer1.0-0 libgstreamer1.0-0-dbg libgstreamer1.0-dev liborc-0.4-0 liborc-0.4-0-dbg liborc-0.4-dev liborc-0.4-doc gir1.2-gst-plugins-base-1.0 gir1.2-gstreamer-1.0 gstreamer1.0-alsa gstreamer1.0-doc gstreamer1.0-omx gstreamer1.0-plugins-bad gstreamer1.0-plugins-bad-dbg gstreamer1.0-plugins-bad-doc gstreamer1.0-plugins-base gstreamer1.0-plugins-base-apps gstreamer1.0-plugins-base-dbg gstreamer1.0-plugins-base-doc gstreamer1.0-plugins-good gstreamer1.0-plugins-good-dbg gstreamer1.0-plugins-good-doc gstreamer1.0-plugins-ugly gstreamer1.0-plugins-ugly-dbg gstreamer1.0-plugins-ugly-doc gstreamer1.0-pulseaudio gstreamer1.0-tools gstreamer1.0-x libgstreamer-plugins-bad1.0-0 libgstreamer-plugins-bad1.0-dev libgstreamer-plugins-base1.0-0 libgstreamer-plugins-base1.0-dev
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top