Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Sound ("Bell")

I'd like to have a python program alert me when it has completed its task by making a beep noise. Currently, I use import os and then use a command line speech program to say "Process complete". I much rather it be a simple "bell."

I know that there's a function that can be used in Cocoa apps, NSBeep, but I don't think that has much anything to do with this.

I've also tried

print(\a) 

but that didn't work.

I'm using a Mac, if you couldn't tell by my Cocoa comment, so that may help.

like image 439
stalepretzel Avatar asked Aug 17 '08 21:08

stalepretzel


People also ask

How do you make a ding in Python?

Using the Bell Character to Make Beep Sound in Python One of the simplest ways to generate a beep sound is to use the bell character i-e '\a' within the print statement. This method does not require any extra package to import.

What is bell character in Python?

In the programming languages C (created in 1972) and Python (created in 1991), the bell character can be placed in a string or character constant with \a . ('a' stands for "alert" or "audible" and was chosen because \b was already used for the backspace character.)


1 Answers

Have you tried :

import sys sys.stdout.write('\a') sys.stdout.flush() 

That works for me here on Mac OS 10.5

Actually, I think your original attempt works also with a little modification:

print('\a') 

(You just need the single quotes around the character sequence).

like image 146
gbc Avatar answered Sep 22 '22 05:09

gbc