Python Sound (“Bell”)

后端 未结 6 1042
无人共我
无人共我 2020-11-29 04:03

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 spee

6条回答
  •  粉色の甜心
    2020-11-29 04:28

    Building on Barry Wark's answer... NSBeep() from AppKit works fine, but also makes the terminal/app icon in the taskbar jump. A few extra lines with NSSound() avoids that and gives the opportunity to use another sound:

    from AppKit import NSSound
    #prepare sound:
    sound = NSSound.alloc()
    sound.initWithContentsOfFile_byReference_('/System/Library/Sounds/Ping.aiff', True)
    #rewind and play whenever you need it:
    sound.stop() #rewind
    sound.play()
    

    Standard sound files can be found via commandline locate /System/Library/Sounds/*.aiff The file used by NSBeep() seems to be '/System/Library/Sounds/Funk.aiff'

提交回复
热议问题