2

I am trying to create a little timer program that will have the user's computer beep when the timer is finished.

Being on a Mac, the winsound library is not available, and I cannot get \a to generate any noise at all.

How would I go about generating a little ding or beep or some other sound when the timer is finished?

millionsunz
  • 21
  • 1
  • 2
  • what python are you using? are you running it on the terminal or somwehere else? – PYA Jul 16 '17 at 01:44
  • Are you trying `\a` from inside Python? Remember that `\a` can also be used from the Terminal in Mac by using `printf "\a"` at the prompt. So, if I were you, I would try ` >>> import os >>> os.system("printf \"a\"")` This should print a 0 and generate a beep sound, assuming your speaker and sound drivers are working fine, and your Mac is not muted. – KuboAndTwoStrings Jul 16 '17 at 01:55
  • If you want to be more fancy, just execute `afplay `. This is of course os specific to os x. – Grimmy Jul 16 '17 at 02:03

1 Answers1

0

try this:

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

works for me

Mauricio
  • 419
  • 4
  • 14
  • 1
    @Zizouz212 I did this on a mac, and had succes because of the call to sys.stdout.flush(). That's what I was trying to portray. Did you make any effort to see what was different about my response? – Mauricio Aug 28 '19 at 04:49