Playing an ogg file on linux using python

March 11, 2010 at 11:02 pm Leave a comment

The following code allows one to repeatedly play a sound sample using python on linux.

This code depends on python-ogg, python-pyvorbis and python-pyao.

import ogg.vorbis
import ao

filename = 'test.ogg'

class OggSample(object):
	def __init__(self, filename):
		id = ao.driver_id('esd')
		self.vf = ogg.vorbis.VorbisFile(filename)
		self.device = ao.AudioDevice(id)

	def play(self):
		while 1:
			buff, bytes, _ = self.vf.read(4096)
			if bytes != 0:
				self.device.play(buff, bytes)
			else:
				self.vf.time_seek(0)
				return

sample = OggSample(filename)
sample.play()
sample.play()

There may well be better ways of doing this : in particular, I’m not sure how much this will cause one to talk to the disk.

Advertisements

Entry filed under: Uncategorized. Tags: , , .

Postgres sql basic querying based on datetime Python ticking clock – Periodically play a ticking sound

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


March 2010
M T W T F S S
« Feb   Apr »
1234567
891011121314
15161718192021
22232425262728
293031  

%d bloggers like this: