How do you play Ogg files in Python on Linux?

Can someone provide an example of a short code or pseudo code on how to play Ogg files in Python 2.7.1 or Python 3.1.3 on Linux (along with a list of any dependencies on the Synaptic package manager or elsewhere)?

+3
source share
3 answers

If you don't mind depending on numpy, my audio lab package works very well and supports oggfile out of the box, while libsndfile itself supports it (it should on linux if your version is quite recent):

# 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 simple:

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

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

+3
source

- python, pygame. http://www.pygame.org/news.html , , ogg , , , libvorbis, , , . , pygame. , . , , .

+1

I used py-gstreamer to play ogg files with the 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
0
source

Source: https://habr.com/ru/post/1787261/


All Articles