Sound alarm when code finishes

前端 未结 11 781
离开以前
离开以前 2021-01-29 17:42

I am in a situation where my code takes extremely long to run and I don\'t want to be staring at it all the time but want to know when it is done.

How can I make the (Py

相关标签:
11条回答
  • 2021-01-29 18:27

    Kuchi's answer didn't work for me on OS X Yosemite (10.10.1). I did find the afplay command (here), which you can just call from Python. This works regardless of whether the Terminal audible bell is enabled and without a third-party library.

    import os
    os.system('afplay /System/Library/Sounds/Sosumi.aiff')
    
    0 讨论(0)
  • 2021-01-29 18:30
    import subprocess
    
    subprocess.call(['D:\greensoft\TTPlayer\TTPlayer.exe', "E:\stridevampaclip.mp3"])
    
    0 讨论(0)
  • 2021-01-29 18:31

    A bit more to your question.

    I used gTTS package to generate audio from text and then play that audio using Playsound when I was learning webscrapping and created a coursera downloader(only free courses).

    text2speech = gTTS("Your course " + course_name +
                                    " is downloaded to " + downloads + ". Check it fast.")
    text2speech.save("temp.mp3")
    winsound.Beep(2500, 1000)
    playsound("temp.mp3")
    
    0 讨论(0)
  • 2021-01-29 18:32

    ubuntu speech dispatcher can be used:

    import subprocess
    subprocess.call(['speech-dispatcher'])        #start speech dispatcher
    subprocess.call(['spd-say', '"your process has finished"'])
    
    0 讨论(0)
  • 2021-01-29 18:34

    I'm assuming you want the standard system bell, and don't want to concern yourself with frequencies and durations etc., you just want the standard windows bell.

    import winsound
    winsound.MessageBeep()
    
    0 讨论(0)
提交回复
热议问题