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.
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.
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.)
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With