Using only the modules that come with a standard python 2.6 installation, would it be possible to play a simple beeping noise?
Asked
Active
Viewed 5.1k times
29
-
See: http://stackoverflow.com/questions/13941/python-sound-bell – perimosocordiae Dec 17 '10 at 02:47
-
So I would have to go through the default os's speech to text program? Also I am not using a mac all of the time. This would have to be cross platform. – a sandwhich Dec 17 '10 at 02:52
-
1@a sandwhich: Read the *answers* at the link, not the question. – Greg Hewgill Dec 17 '10 at 02:55
3 Answers
38
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.

David Wolever
- 148,955
- 89
- 346
- 502
-
8
-
also works on macs however it uses your speaker so if say you have headphones in it will use your headphones or if it is muted it won't work. – Zimm3r Dec 15 '13 at 03:18
-
-
what is the main difference between `print "\a"` and `sys.stdout.write("\a")`? – Mathias711 Jun 27 '14 at 12:07
-
3@Mathias711 that… is actually a more complex question than it seems. In this case, `print "\a"` is basically the same as `sys.stdout.write("\a\n")`; `sys.stdout.write("\a")` won't always work because `sys.stdout` is usually line buffered (so you won't "see" the write until a newline is written). For more, see http://stackoverflow.com/questions/3263672/python-the-difference-between-sys-stdout-write-and-print – David Wolever Jul 03 '14 at 16:12
19
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/

user3394963
- 359
- 3
- 7
2
On Android with QPython this is how it goes:
import androidhelper
droid=androidhelper.Android()
droid.generateDtmfTones('0',100)
This will place a beep of a certain frequency for certain time.

Hardik Kumar Sinha
- 37
- 1
- 9

Vektast
- 21
- 3
-
1It's `generateDtmfTones()`. You're missing an `f`. https://kylelk.github.io/html-examples/androidhelper.html – Shayan Jul 04 '21 at 13:20