The Artima Developer Community
Sponsored Link

Web Buzz Forum
Playing system sounds from Python programs on Ubuntu

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Stuart Langridge

Posts: 2006
Nickname: aquarius
Registered: Sep, 2003

Stuart Langridge is a web, JavaScript, and Python hacker, and sometimes all three at once.
Playing system sounds from Python programs on Ubuntu Posted: Dec 21, 2010 2:42 AM
Reply to this message Reply

This post originated from an RSS feed registered with Web Buzz by Stuart Langridge.
Original Post: Playing system sounds from Python programs on Ubuntu
Feed Title: as days pass by
Feed URL: http://feeds.feedburner.com/kryogenix
Feed Description: scratched tallies on the prison wall
Latest Web Buzz Posts
Latest Web Buzz Posts by Stuart Langridge
Latest Posts From as days pass by

Advertisement

Jono asked me yesterday how you play a system beep from a Python program on Ubuntu. Now, the way you're meant to play system sounds is by using libcanberra; it's the standard platform library for playing a sound. Sounds come from your sound theme.

A sidebar: themes in Ubuntu

The icons used by your desktop are part of an icon theme. This means that there are a set of names defined for particular things -- there's an icon name for "sound at maximum volume", another name for "sound at minimum volume", another for "wireless network connected", and so on. Then the applications on the desktop use those icons by name, so the Sound indicator displays the "sound at maximum volume" icon in the panel at the top of the screen when your sound's at maximum volume. This means that you can change the look of your desktop by providing a different icon theme (a whole set of icons, named after the specified names), and all your applications use your new icons so they all look consistent. A sound theme works on the same principle; there are a defined set of sounds (there's one for "your battery is low", one for "a window has been maximised", one for "you have logged in", and so on), and your sound theme defines what those sounds are. So you can switch in a different sound theme, and now all your applications will change to use the sounds from your sound theme. End of sidebar.

What all this boils down to is that you ought to be able to play the standard warning sound by telling libcanberra to "play a sound named dialog-warning", and it'll play the correct sound.

However, there isn't a Python version of libcanberra, sad to say. I complained about this on twitter, and psykoyiko brilliantly responded with a pointer to a Python libcanberra library he wrote: pycanberra.py. So, you can now play system sounds from your Python program, because this is basically a set of Python bindings for libcanberra.

To play a sound:

import pycanberra
canberra = pycanberra.Canberra()
canberra.easy_play_sync("dialog-warning")
canberra.destroy()

Hooray! Good job psykoyiko! Someone should get this into Ubuntu.

Read: Playing system sounds from Python programs on Ubuntu

Topic: Alien Arena 2011 Released Previous Topic   Next Topic Topic: Get One Year Free Subscription of BullGuard Antivirus Costs £ 24.95

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use