473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

beeping under linux

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
Jul 18 '05 #1
5 24937
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

Jul 18 '05 #2
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
Assuming you mean 'print "\a"' (ASCII BEL) rather than 'print "\b"'
(ASCII BS), this is the most portable way to sound the terminal bell.

Most responses have been talking about /dev/audio, which is unrelated to
the terminal bell and is not portable -- many systems, especially
headless ones, do not have any sound card.
[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]


The correct way to do this is to send the ASCII BEL ("\a") character to
the terminal. If the terminal's bell has been disabled somehow, it's
not the job of your program to revert that decision.

--
\ "I always wanted to be somebody. I see now that I should have |
`\ been more specific." -- Lily Tomlin |
_o__) |
Ben Finney <http://bignose.squidly.org/>
Jul 18 '05 #3
Alexander Schmolck <a.********@gmx.net> wrote in message news:<yf*************@black132.ex.ac.uk>...
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/).
[cape:1:dw]$ setterm -blen 1234 -bfreq 4321 | xxd
0000000: 1b5b 3131 3b31 3233 345d 1b5b 3130 3b34 .[11;1234].[10;4
0000010: 3332 315d 321]
[cape:2:dw]$ echo $TERM
linux

If by 'reliably', you mean 'override the users choice of having the
speaker on or off', then I think you need a rethink. :)

There are several utilities about that can do the beeping (and music)
for you, and IIRC even ones that work across platforms.

[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]


Suggestion: allow a configurable command to be called, so that users
can choose their own notification method, eg. /usr/bin/play (a part of
'sox').
David.
Jul 18 '05 #4
dw***********@botanicus.net (David M. Wilson) writes:
Alexander Schmolck <a.********@gmx.net> wrote in message news:<yf*************@black132.ex.ac.uk>...
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/).
If by 'reliably', you mean 'override the users choice of having the
speaker on or off', then I think you need a rethink. :)


Being the (sole) user (and not suffering from multiple personality disorder),
such an override seems unlikely.

As I mentioned in my reply to Ben Finney, apart from the fact that I simply
have no idea how to configure comint (or kterm for that matter -- cerainly not
via settings-bell) for (audible) beeping, for this particular scenario
(notification of myself when I'm not necessarily in front of my computer) the
standard terminal bell preference settings are not really that relevant
anyway.

There are several utilities about that can do the beeping (and music)
for you, and IIRC even ones that work across platforms.
Great, do you know one for linux (that uses the internal speaker and that
ideally would be preinstalled or come as a Mandrake rpm)?

[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]


Suggestion: allow a configurable command to be called, so that users
can choose their own notification method, eg. /usr/bin/play (a part of
'sox').


Sure, I just don't know any suitable command/program.

'as
Jul 18 '05 #5
Ben Finney <bi****************@and-benfinney-does-too.id.au> writes:
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
Assuming you mean 'print "\a"' (ASCII BEL) rather than 'print "\b"'
(ASCII BS), this is the most portable way to sound the terminal bell.


Anything that works under a normal linux box will do.
Most responses have been talking about /dev/audio, which is unrelated to
the terminal bell and is not portable -- many systems, especially
headless ones, do not have any sound card.
Yep -- and although mine does have a soundcard it has no speakers.
The correct way to do this is to send the ASCII BEL ("\a") character to
the terminal. If the terminal's bell has been disabled somehow, it's
not the job of your program to revert that decision.


Well, I happen to see myself as the ultimate authority on what my program's
job (especially when I'm the sole user) and I also fail to discern an obvious
relationship between my user-preference for visible/audible bells when working
with (i.e. in front of) a certain terminal and my desire to receive some
notification when a long-running process finishes that doesn't force me to
constantly monitor the monitor (because chances are I might be reading a
paper).

I could live with a solution that requires me to change comint's (viz Emacs's
py-shell's) and kterm's beeping behavior before and after my program runs, but
I have no idea to get either of them to beep audibly (kterms bell settings
e.g. don't seem much of a help).

The best reason I can see for trying to find a way to make '\a' work is that
it would be desirable to have beeping behavior also for remotely running
processes (so directly writing to /dev/* or some such wouldn't be ideal).

'as
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jhuola Hoptire | last post by:
Just installed J2RE 1.4.2 on a Linux server. I am very knew to the POSIX world. I couldn't dig-up much in the docs or via google about the following: 1 - Is there a standard way to make sure...
1
by: Herman Geldenhuys | last post by:
I am dialing a modem(COM3) from python on windoze and I connect successfully to a remote phone, but there is an annoying beeping sound that keeps on ringing in the background. Would anybody happen to...
4
by: Jim | last post by:
Hello, I'd like to emit beeps. The twists are that (1) I hope to have control over the frequency of the beeps and their duration and (2) I'd like the solution to be portable across Linux,...
0
by: Eric Raymond | last post by:
When installing the rpms (or the tar file) onto Red Hat Enteprise Linux AS Beta 1 (Taroon), we get the follwing error: Installing all prepared tables /usr/bin/mysql_install_db: line 1: 7690...
5
by: cranium.2003 | last post by:
hi, Here is my code #include <iostream.h> int main() { cout <<"HI"; return 0; } and using following command to compile a C++ program g++ ex1.cpp -o ex1
0
by: adrian | last post by:
Hi, I'm using SnmpSendMsg from within VB.net 2005, everything is working fine but occasionally calling SnmpSendMsg causes a system exclamation beep. As I'm querying several values this causes...
9
Subsciber123
by: Subsciber123 | last post by:
I am running a program that I wrote (a compression program {it is not finished yet}), and when I run it, my computer makes a continuous beeping sound (the same sound your computer makes if you press...
1
by: tvnaidu | last post by:
MY PC (windows 2000 prof) keep beeping - if I mute audio also beeping - looklike motherboard beeping. It just started today, earlier no beep at all, suddenly started. any diagnostic tip?....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.