PC speaker - ArchWiki

Jump to content

# PC speaker

From ArchWiki

Related articles

- Kernel modules
- Advanced Linux Sound Architecture

Ever since the first IBM PC most PCs have a built-in PC speaker (or beeper) which may produce beeps. This speaker is not capable of high quality playback and merely serves as a simple means of auditory feedback in the form of beeps. Some software, e.g. web browsers, editors and terminals, may produce beeps which may or may not be desired by the user. Hence this article serves as a guide on how to configure or even disable those beeps.

For situations where no sound card or speakers are available and a simple audio notification is desired, see #Beep.

## Mechanism

The PC speaker is typically a physical unit connected on the front connections header of the motherboard. Some motherboard manufacturers do not ship their motherboards with a PC speaker at all, whereas others may have the PC speaker soldered directly onto the surface. Laptops typically have no physical PC speaker but have the beeper routed to the laptop's internal speakers. In some cases, the beeper is heard on the regular output (i.e. speakers, headphones) of the soundcard, which tends to be unexpectedly loud.

Upon boot the BIOS will traditionally generate a beep during POST. More recent motherboard models omit the POST beep in favor of rapidly booting into the OS. The BIOS typically allows for toggling the POST beeps but it cannot configure the PC speaker to be turned off completely.

Once the system has booted into Linux and the `pcspkr` kernel module is loaded, the PC speaker can be used by the environment, be invoked manually by the user, and be configured to some extent. Because the PC speaker is controlled directly by the CPU, along with the fact that they are built for beeping only, PC speakers cannot be used for playing back audio.

## Disabling the PC speaker

Turning off a particular instance of a sound, while leaving the others operational, is possible if and only if one can identify which portion of the environment generates the particular sound. This allows customizing the selection of sounds. Please feel free to add any configurations and settings to this wiki page that may be useful for other users.

### Globally

By removing the PC speaker the system will not be able to produce beeps. This can be achieved by physically removing the unit from the motherboard (if possible). Some manufacturers may provide a jumper header to switch it off.

Warning: Removing the PC speaker is generally not recommended as it is a useful tool in diagnosing boot problems, after which it may produce a unique beeping pattern related to the source of fault (refer to your motherboard manual). A better solution is to turn off the POST beeps in the BIOS and blacklisting the beeper as written below. If you do however wish to remove it physically it is highly recommended to keep it at bay for this scenario.

### In Linux

The PC speaker can be disabled by unloading the `pcspkr` kernel module:

    # rmmod pcspkr

Blacklisting the `pcspkr` module will prevent udev from loading it at boot. Create the file:

    /etc/modprobe.d/nobeep.conf

    blacklist pcspkr

Blacklisting it on the kernel command line is yet another way. Simply add `modprobe.blacklist=pcspkr` to your bootloader's kernel line.

### Console

You can add this command in `/etc/profile` or a dedicated file like `/etc/profile.d/disable-beep.sh`:

    setterm -blength 0

Another way is to uncomment or add this line in `/etc/inputrc` or `~/.inputrc`:

    set bell-style none

#### Less pager

To disable PC speaker in less pager, you can launch it with `less -q` to mute PC speaker for end of line events or `less -Q` to mute it altogether. For man pages, launch `man -P "less -Q"` or set the `$MANPAGER` or `$PAGER` environment variables.

Alternatively, you can add these lines to your `~/.bashrc`:

    alias less='less -Q'
    alias man='man -P "less -Q"'

### Xorg

    $ xset -b

You can add this command to a startup file such as `/etc/xprofile` to make it permanent. See xprofile for more information.

### ALSA

For most sound cards the PC speaker is listed as an ALSA channel, named either PC Speaker, PC Beep, or Beep. To mute the speaker, either use `alsamixer` or `amixer` , for example:

    $ amixer set 'PC Speaker' 0% mute

To unmute the channel, see Advanced Linux Sound Architecture#Unmuting the channels.

Tip: If you are using PulseAudio and the PC speaker channel is not listed for the default ALSA device, try selecting the device corresponding to the sound card - PulseAudio proxy controls may not list the PC speaker.

### GNOME

Using GSettings:

    $ gsettings set org.gnome.desktop.wm.preferences audible-bell false

### KDE Plasma

Bell notification settings can be modified in "System Settings"->"Accessibility Options"->"Bell".

### Cinnamon

Cinnamon seems to play a "water drop" sound. To disable it, set in gsettings(1):

    $ gsettings set org.cinnamon.desktop.wm.preferences audible-bell false

### GTK

Append this line to `~/.gtkrc-2.0`:

    gtk-error-bell = 0

Add the same line to the [Settings] section of `$XDG_CONFIG_HOME/gtk-3.0/settings.ini`:

    [Settings]
    gtk-error-bell = 0

This is documented in the Gnome Developer Handbook.

### PulseAudio

Play a sound instead of a PC speaker beep using PulseAudio.

## Beep

A user can create a short audible tone when logged in to a virtual console. See Wikipedia:bell character#usage for the details.

Beep is an advanced PC speaker beeping program. It is useful for situations where no sound card and/or speakers are available, and simple audio notification is desired.

### Installation

Install the beep package.

You may also need to unmute the PC speaker in ALSA.

### Run as non-root user

`beep` uses `/dev/input/by-path/platform-pcspkr-event-spkr` to control the PC speaker. To access it as a non-root user, one has to set the proper permissions. Create `/etc/udev/rules.d/70-pcspkr-beep.rules` and add the following rule:

    ACTION=="add", SUBSYSTEM=="input", ATTRS{name}=="PC Speaker", ENV{DEVNAME}!="", TAG+="uaccess"

That will allow any user, who is logged into the currently active virtual console session, to use the PC speaker.

Alternatively, a new user group may be created (e.g. `beep`) with the corresponding rule to set the right permissions on the device file:

    ACTION=="add", SUBSYSTEM=="input", ATTRS{name}=="PC Speaker", ENV{DEVNAME}!="", GROUP="beep", MODE="0620"

With that solution any user in the `beep` group will be able to control the speaker.

To force reloading rules and device file to apply new user permission without a reboot, execute:

    $ udevadm control --reload && rmmod pcspkr && modprobe pcspkr

### Tips and Tricks

While many people are happy with the traditional beep sound, some may like to change its properties a bit. The following example plays slighly higher and shorter sound and repeats it two times.

    # beep -f 5000 -l 50 -r 2

## See also

- xset(1), setterm(1), bash(1)
- https://github.com/NaWer/beep and https://github.com/ShaneMcC/beeps - repositories collecting bash scripts playing various music using beep

Category:

- Sound