beeping under linux
Christophe Delord
no.spam
Wed Nov 19 18:19:58 EST 2003
Hello,
you can for instance write to /dev/audio
Here is a simple and ugly beep function (not really portable). It builds
a string with a signal having the expected frequency, amplitude (between
0 and 255) and duration (in seconds) :
def beep(frequency, amplitude, duration):
sample = 8000
half_period = int(sample/frequency/2)
beep = chr(amplitude)*half_period+chr(0)*half_period
beep *= int(duration*frequency)
audio = file('/dev/audio', 'wb')
audio.write(beep)
audio.close()
beep(440, 63, 1)
There must be more smarter solutions...
Christophe.
On 19 Nov 2003 19:41:28 +0000, Alexander Schmolck wrote:
> This is only partly a python question, but what is the easiest way to
> get python to (reliably) beep under linux? By reliably I mean that
> ``print "\b"`` won't do because it depends on the terminal settings --
> so I guess I'm looking for some simple way to more or less directly
> access the internal speaker(maybe writing to something in /dev/).
>
> [The usage scenario is simply to have an effective way of signalling
> that a long running-process finshed, without me having to constantly
> look at the screen]
>
> 'as
More information about the Python-list
mailing list