There has been much written on getting the beep sound from Ubuntu releases over the years. Example: fixing the beep

My needs are slightly different in that I do not want to ensure sound card beeps are functioning. Instead, I want PC speaker beeps, the kind produced by the original built-in speaker because I believe they will produce less CPU load. I have confirmed that my computer has the PC speaker by unplugging the external speakers and shutting down Ubuntu. At some point in the shutdown and restart process a beep is heard even though the external speakers have no power.

I have tried the following:

In /etc/modprobe.d/blacklist.conf, turn these lines into comments:

#blacklist snd_pcsp
#blacklist pcspkr

In .bashrc

/usr/bin/xset b on
/usr/bin/xset b 100

Enable in the gnome terminal: Edit > Profile Prefs > General > Terminal Bell

Ensure no "mute" selections in: System > Prefs > Sound > various tabs (uncheck them all).

Select "Enable window and button sounds" in: System > Prefs > Sound > Sound Effects

In gconf-editor desktop > gnome > sound, select the three sound check boxes.

In gconf-editor apps > metacity > general select the audible bell check box.

Still I get no PC speaker beeps when I send code 7 to the console via my Java program or use

echo -e '\a'

or equivalently

echo -e "\a"

on the bash command line. (The -e option means enable escape sequence interpretation.) What else should I try?

Update Since my goal is to minimize load on the CPU, here is a comparison of elapsed times. Each test is for 100,000 iterations. Each variant was performed three times so three results are presented for each.

printwriter.format("%c", 7); 
// 1.3 seconds, 1.5 seconds, 1.5 seconds

// 0.8 seconds, 0.3 seconds, 0.5 seconds

try { Runtime.getRuntime().exec("beep"); } catch (IOException e) { } 
// 10.3 seconds, 16.3 seconds, 11.4 seconds

These runs were done inside Eclipse so multiply by some value less than 1 for standalone execution. Unfortunately, Toolkit's beep is silent on my computer and so is code 7. The beep utility works but has the most cost.

  • I want "echo -e '\a'" to work, too. Because I want to know if a script has termined: foo-script.py; while true; do echo -e '\a'; done – guettli Jan 18 '12 at 16:02
  • I guess your search for a solution (reduce cpu usage) has already created a lot of cpu cycles..... – guettli Jan 18 '12 at 16:04

On my Oneiric system I had to do the following to get XBell/XkbBell working again:

  1. Load the module pcspkr (like you already did via /etc/modprobe.d/blacklist.conf)
  2. Remove the package pulseaudio-module-x11 (that seems to absorb all XBell events)
  3. Put options snd-hda-intel beep_mode=2 into /etc/modprobe.d/enable-beep.conf (you only need that case you own a system with an intel sound chip like my Latitude E6420). Unmute the speaker in alsamixer after that.

Some terminals (like konsole, see bug Bug 177861) ignore the bell character. A good way to test the system beep is with the xkbbell command.

After I did all that the java call Toolkit.getDefaultToolkit().beep() works just fine.

| improve this answer | |
  • That works for me, by just loading kernel module sudo modprobe pcspkr, It does work with echo -e '\a', xkbbell, beep and using XBell() & XkbBell() c functions. Some posts montion requirement ofmodule-x11-bell with pulseaudio, I unloaded it and it worked. One thing that I could find to stop it is dconf write /org/gnome/desktop/wm/preferences/audible-bell false or from Compiz>GeneralOptions>AudibleBell. As it seems for now, the bell is a Windows Manager task. I'm using Ubuntu 14.04 – user.dz Jan 18 '15 at 13:36
  • Thank you! My Dell 7270 beeps like a boss! – nachopro Jun 14 '19 at 14:23

On 14.04.3 LTS it nows seems sufficient to edit /etc/modprobe.d/blacklist.conf and enable pcspkr by commenting out the blacklist line.

#blacklist pcspkr

The # turns the line into a comment.

Make sure the Terminal (gnome-terminal) allows console bell in the preferences tab.

This was tested via backspace on an empty terminal line. This was also tested via the beep utility (assuming that you have installed it). Instead you can do programmatic beeping via the java.awt.Toolkit object:


The Toolkit object is more efficient than the beep utility.

By the way, some people dislike the PC speaker. Link

| improve this answer | |

Make sure your terminal and theme don't eat the event.

External tools work, you say. You could dive into their code. This might help.

| improve this answer | |

Use the beep program (http://johnath.com/beep/), i've compiled the v1.3, because the 1.2.2 in Lucid repositories do not work.

  • you need to run it with sudo
  • the pcspkr module must be loaded, as you all ready did
| improve this answer | |
  • I don't think you need sudo for the beep utility. The trouble with it is that Runtime.getRuntime().exec("beep"); is how I have been doing it in Java. Might be slow compared to code 7 to the standard output. – H2ONaCl Jan 18 '12 at 14:22
  • 1
    without sudo gives Could not open /dev/tty0 or /dev/vc/0 for writing open: No such file or directory – playerum Jan 18 '12 at 14:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.