Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am writing a small reminder-app and want to play a system sound once the timer has reached 0. What is the easiest way to play that sound, and which sound would you recommend?

share|improve this question

1 Answer 1

up vote 13 down vote accepted

The easiest way would probably be to shell out:

system("/usr/bin/canberra-gtk-play --id='bell'")

This will work in other programming languages as well.

/usr/bin/canberra-gtk-play will play a sound from the current sound theme. See the freedesktop.org sound naming spec for a list of available sounds and their meanings. Beware that (as far as I know) there isn't a sound theme that provides all of these sounds.

Use ls /usr/share/sounds/ubuntu/stereo to see what sounds are supported by the 'ubuntu' sound theme which is default, and rarely changed (due to no easy way to install sound themes) on Ubuntu.

share|improve this answer
    
Thanks! Do you have any hint on where I can find more ids? Because 'bell' does not really suit me. –  Ingo Nov 3 '10 at 20:23
    
See updated answer. –  dv3500ea Nov 3 '10 at 20:24
6  
For safety, I recommend using subprocess. String-based execution can lead to dangerous situations. For example: import subprocess; subprocess.call(['/usr/bin/canberra-gtk-play','--id','bell']) –  Kees Cook Nov 3 '10 at 20:24
    
@Kees Cook, Please explain how executing the above command via system() can lead to "dangerous situations". –  Cerin Mar 15 '12 at 15:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.