Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > howto do a robust simple cross platform beep

Reply
Thread Tools

howto do a robust simple cross platform beep

 
 
Gelonida N
Guest
Posts: n/a
 
      07-14-2012
Hi,


I just want to use a beep command that works cross platform.


I tried the simplest approach (just printing the BEL character '\a'
chr(7) to the console.


This fails on my Ubuntu 12.04 host, as the pcspkr is in the list of the
blacklisted kernel modules.

I found another snippet trying to push a sine wave directly to /dev/audio

but I don't have write permissions to /dev/audio.

Other solutions seem to suggest to play a wav file, but of course first
I had to write code creating me a wav file.

How do others handle simple beeps?


I just want to use them as alert, when certain events occur within a
very long running non GUI application.


Thanks for any info.


What I do at the moment is:

For Windows I use winsound.Beep

For Linux I create some raw data and pipe it into sox's
'play' command.

I don't consider this very elegant.











 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      07-14-2012
On Sat, 14 Jul 2012 03:00:05 +0200, Gelonida N wrote:

> How do others handle simple beeps?
>
> I just want to use them as alert, when certain events occur within a
> very long running non GUI application.


Why? Do you hate your users?


> What I do at the moment is:
>
> For Windows I use winsound.Beep
>
> For Linux I create some raw data and pipe it into sox's 'play' command.
>
> I don't consider this very elegant.


There is no cross-platform way to play a beep.

Every few years, people complain that Python doesn't have a standard way
to play a simple alert sound. Why ask for volunteers to write and
maintain the code, and suddenly they go silent.


--
Steven
 
Reply With Quote
 
 
 
 
Dieter Maurer
Guest
Posts: n/a
 
      07-14-2012
Steven D'Aprano <(E-Mail Removed)> writes:
>> How do others handle simple beeps?
>>
>> I just want to use them as alert, when certain events occur within a
>> very long running non GUI application.

>
> Why? Do you hate your users?


I, too, would find it useful -- for me (although I do not hate myself).

Surely, you know an alarm clock. Usually, it gives an audible signal
when it is time to do something. A computer can in principle be used
as a flexible alarm clock - but it is not so easy with the audible signal...
An audible signal has the advantage (over a visual one) that you can
recognize it even when you are not looking at the screen (because you
are thinking).

Unfortunately, I had to give up. My new computer lacks a working
speaker...

 
Reply With Quote
 
Miki Tebeka
Guest
Posts: n/a
 
      07-14-2012
> How do others handle simple beeps?
http://pymedia.org/ ?

I *think* the "big" UI frameworks (Qt, wx ...) have some sound support.
 
Reply With Quote
 
Miki Tebeka
Guest
Posts: n/a
 
      07-14-2012
> How do others handle simple beeps?
http://pymedia.org/ ?

I *think* the "big" UI frameworks (Qt, wx ...) have some sound support.
 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      07-14-2012
On Sun, Jul 15, 2012 at 3:54 AM, Dieter Maurer <(E-Mail Removed)> wrote:
> I, too, would find it useful -- for me (although I do not hate myself).
>
> Surely, you know an alarm clock. Usually, it gives an audible signal
> when it is time to do something. A computer can in principle be used
> as a flexible alarm clock - but it is not so easy with the audible signal...
> An audible signal has the advantage (over a visual one) that you can
> recognize it even when you are not looking at the screen (because you
> are thinking).
>
> Unfortunately, I had to give up. My new computer lacks a working
> speaker...


There's a simple cheat you can do. Just invoke some other application
to produce the sound! My current alarm clock comes in two modes: it
either picks a random MIDI file from Gilbert and Sullivan's
"Ruddigore", or it plays the "Alice: Madness Returns" theme; in each
case it just invokes the file with its default association (see the
"start" command in Windows, or "gnome-open" in, well, GNOME).

Of course, working speaker IS a prerequisite.

ChrisA
 
Reply With Quote
 
Hans Mulder
Guest
Posts: n/a
 
      07-15-2012
On 14/07/12 20:49:11, Chris Angelico wrote:
> On Sun, Jul 15, 2012 at 3:54 AM, Dieter Maurer <(E-Mail Removed)> wrote:
>> I, too, would find it useful -- for me (although I do not hate myself).
>>
>> Surely, you know an alarm clock. Usually, it gives an audible signal
>> when it is time to do something. A computer can in principle be used
>> as a flexible alarm clock - but it is not so easy with the audible signal...
>> An audible signal has the advantage (over a visual one) that you can
>> recognize it even when you are not looking at the screen (because you
>> are thinking).
>>
>> Unfortunately, I had to give up. My new computer lacks a working
>> speaker...

>
> There's a simple cheat you can do. Just invoke some other application
> to produce the sound! My current alarm clock comes in two modes: it
> either picks a random MIDI file from Gilbert and Sullivan's
> "Ruddigore", or it plays the "Alice: Madness Returns" theme; in each
> case it just invokes the file with its default association (see the
> "start" command in Windows, or "gnome-open" in, well, GNOME).
>
> Of course, working speaker IS a prerequisite.


The other prerequisite is that the use is physically near the
compueter where your Python process is running.

If, for exmple, I'm ssh'ed into my webserver, then sending a sound
file to the server's speaker may startle someone in the data centre,
but it won't attract my attention. If, OTOH, you do:

print "\7"

, then an ASCII bell will be sent across the network, and my
terminal emulator will beep.

It all depends.


-- HansM


 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      07-15-2012
On Sun, Jul 15, 2012 at 10:39 AM, Hans Mulder <(E-Mail Removed)> wrote:
> The other prerequisite is that the use is physically near the
> compueter where your Python process is running.
>
> If, for exmple, I'm ssh'ed into my webserver, then sending a sound
> file to the server's speaker may startle someone in the data centre,
> but it won't attract my attention. If, OTOH, you do:
>
> print "\7"
>
> , then an ASCII bell will be sent across the network, and my
> terminal emulator will beep.
>


Sure, though other of the OP's ideas preclude that too. But you could
use any network protocol that acknowledges sound (MUDs use \7
following the terminal).

ChrisA
 
Reply With Quote
 
rantingrickjohnson@gmail.com
Guest
Posts: n/a
 
      07-15-2012
On Friday, July 13, 2012 8:00:05 PM UTC-5, gelonida wrote:
> I just want to use a beep command that works cross platform. [...] I
> just want to use them as alert, when certain events occur within a
> very long running non GUI application.


I can see a need for this when facing a non GUI interface. But even "IF" you do manage to play a sound in a cross platform manner; if the speaker volume is too low, or the speakers are turned off, or the computer does not have speakers connected, etc... your user will never hear the alert! In this case, beeping the built-in speaker has the fail-safe advantage.

Why not wrap up the functionality and release a module yourself? If you arenot sure how to access the speaker on one or more OSs then ask on the list.. I would love to see some community effort behind this.

PS: Better make sure this module does not exist though

 
Reply With Quote
 
rantingrickjohnson@gmail.com
Guest
Posts: n/a
 
      07-15-2012
On Friday, July 13, 2012 8:00:05 PM UTC-5, gelonida wrote:
> I just want to use a beep command that works cross platform. [...] I
> just want to use them as alert, when certain events occur within a
> very long running non GUI application.


I can see a need for this when facing a non GUI interface. But even "IF" you do manage to play a sound in a cross platform manner; if the speaker volume is too low, or the speakers are turned off, or the computer does not have speakers connected, etc... your user will never hear the alert! In this case, beeping the built-in speaker has the fail-safe advantage.

Why not wrap up the functionality and release a module yourself? If you arenot sure how to access the speaker on one or more OSs then ask on the list.. I would love to see some community effort behind this.

PS: Better make sure this module does not exist though

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: howto do a robust simple cross platform beep Jerry Hill Python 0 07-24-2012 10:03 PM
Robust, Cross-Browser setAttribute()? Martin Rinehart Javascript 10 11-25-2008 12:54 PM
Seeking robust cross-browser keyboard event handler Matt Kruse Javascript 0 08-15-2006 04:58 PM
Mac LC475 (Quadra 650) plays "beep beep beep beep" Uplink Computer Information 0 04-12-2006 10:37 PM
BEEP! BEEP! BEEP! Arg! :( Kevin Low Computer Information 0 07-06-2003 08:29 AM



Advertisments