Play simple beep with python without external library

后端 未结 3 1687
不思量自难忘°
不思量自难忘° 2020-12-13 14:33

Using only the modules that come with a standard python 2.6 installation, would it be possible to play a simple beeping noise?

相关标签:
3条回答
  • 2020-12-13 14:47

    On Android with QPython this is how it goes:

    import androidhelper
    droid=androidhelper.Android()
    droid.generateDtmTones('0',100)
    
    0 讨论(0)
  • 2020-12-13 14:58

    On windows:

    import winsound         # for sound  
    import time             # for sleep
    
    winsound.Beep(440, 250) # frequency, duration
    time.sleep(0.25)        # in seconds (0.25 is 250ms)
    
    winsound.Beep(600, 250)
    time.sleep(0.25)
    

    34.4. winsound — Sound-playing interface for Windows:

    http://docs.python.org/2.6/search.html?q=sound&check_keywords=yes&area=default

    See also: Clear screen and beep for various platforms. (Python recipe) http://code.activestate.com/recipes/577588-clear-screen-and-beep-for-various-platforms/

    0 讨论(0)
  • 2020-12-13 15:07

    If you're on a Unix terminal, you can print "\a" to get a terminal bell:

    >>> def beep():
    ...     print "\a"
    >>> beep()
    

    Of course, that will print a newline too… So sys.stdout.write("\a") might be better. But you get the idea.

    0 讨论(0)
提交回复
热议问题