473,805 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 25012
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*fr equency)
audio = file('/dev/audio', 'wb')
audio.write(bee p)
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***********@b otanicus.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
2825
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 users (all, or some) can "reach" java? eg one could presumably create a java.sh or aliases ... Where is the standard Linux directory to put such a script (and why)?
1
1848
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 know what command and in what sequence I should send to the modem to make it stop? Thanks H
4
2832
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, Windows, and OS X. I've done some searching of this group and the solutions that people have offered in the past seem not to satisfy both points. For instance, that I can tell, "\a" or curses.beep() doesn't give you control over the frequency or...
0
2389
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 Segmentation fault /usr/sbin/mysqld --bootstrap --skip-grant-tables --basedir=/ --datadir=/var/lib/mysql --skip-innodb --skip-bdb Installation of grant tables failed The log file simply shows a start and a stop of the server.
5
5692
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
1119
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 repeated beeping for no appearent reason as the call functions correctly. A reboot seems to clear the problem but it would be nice to know the
9
6605
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 too many keys at once on the keyboard {in windows}). What is the cause of this beeping noise?
1
3354
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?. appreciated.
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.