PC speaker

About the PC Speaker
The PC Speaker is more commonly referred to the speaker located on the motherboard. Nowadays this speaker is usually a simple piezoelectric speaker, with the piezoelectric speaker providing just enough speaker hardware to distinguish simple frequency and tones of beeps. Beeps usually occur on error, but can be customized as this article will document.

PC Speaker Kernel Driver
Make sure your motherboard has two pins for the PC speaker, as well as being connected to a small speaker or piezoelectric speaker.

Build the Linux kernel module, named INPUT_PCSPKR, located within the folder architecture of Drivers > Input > Miscellaneous devices folder of menuconfig.

NOTE: It is common most users finding an easy way of disabling this so-called annoying device, by simply black listing the module within the /etc/modprobe.d/blacklist.conf, so ensure the loading of this module is not inhibited by such configurations.

PC Speaker Configuration Files and Settings
Activation of the PC Speaker after ensuring the module is either built statically linked within the kernel or loaded, also include several settings are activated.

Util-Linux Utility
While within the Linx console or terminal, use the following. setterm -blength <0-2000> setterm -bfreq freqnumber

XOrg XSet Utility
While within X11/Xorg, use the following.

Query current XSet options

For users of the old PC keyboards having a speaker, users can easily activate a typewriting sound effect after each key press by doing:

Should show "key click percent: 100", for key clicks being activated.

GNU Screen
By default, GNU Screen enabled audible bell style, unless visual style is activated. So disable visual style:

From within GNU Screen, 'CTRL-a CTRL-g' can switch visual or audible bell styles.

Beep
There's a program which simplifies playing and customizing frequencies of beeps through the PC Speaker

XKBUtils
For historical purposes, providing only a simple bell or monotone beep, xkbbell.

On Demand via Console or Script
On demand use of the PC speaker can be accomplished by using a simple echo statement using an escape sequence indicating the command line terminal to process a beep.

This echo statement is commonly placed within scripts and programs, to either indicate the task has finished, or has exited on error.

Johnath's Beep
Johnath's beep utility, mentioned above and provided by the Gentoo app-misc/beep package; provides frequency, length, delay, along with a few other much desired features. However seems to lack volume control. My guess the volume might be muddled in with the frequency of the beep.

See the bottom of the beep's manual page for further examples.

Typewriter Effect
If you're unfortunate like the many of us nowadays and do not own a keyboard having a speaker for using "xset c", then you'll need to either script or program something, taking the keyboard events and playing a beep or sound.

The following options can either use app-misc/beep for simplicity and using fewer system resources, or use alsa-utils aplay for playing more dramatic effects. (Or insert your other favorite command line media player such as afplay for playing AIFF files.)

Bourne Shell or BASH
A simple Bourne Shell or BASH script utilizing app-misc/beep.

Where xinput test argument is your AT Keyboard, extracted from "xinput --list", pipe the output to an infinite while variable (or until CTRL-C is pressed). Read each line via read and perform a REGEX search for lines containing "press" and if found use the beep command.

FIXME: Trying to alias the previous incantation within $HOME/.bashrc within double fails, likely due to *press* not being within quotes. Specifying the incantation within single quotes as an alias works.

FIXME: Trying to pipe the 'xinput' output to 'cut -b 5-' then to the infinite read while loop fails. This would be for using an if/then to omit modifier keys.

FIXME: If further omitting modifier keys (for which would be nice and more realistic), should condense the script to reduce the number of time consuming System or CPU processes.

VIM
Fortunately, VIM can be made to sound like a typewriter as you're typing by a simple vimrc script. From here, I use app-misc/beep for simplicity.

Python
Insert your favorite (if you must) very simplified Python script here.

No PC Speaker beeps or sounds
Make sure your motherboard has a speaker pin outputs along with a speaker attached, check your BIOS PC Speaker or BIOS Keyboard settings for older hardware, and make sure the pcspkr module is not blacklisted. Use the setterm and xset utilities above for increasing the beep length, and ensure GNU Screen is not using the visual bell. All this has been documented above.

Playing musical notes on the PC Speaker
See the package app-misc/beep manual page. (ie. man beep)

Toward the end of the beep manual page, is documentation corresponding approximate frequency correlations for each of the musical scale notes.

How do I mute the PC Speaker?
Some methods for disabling the PC Speaker:
 * The easy method, and once and for all solution for muting the PC speaker, add the pcspkr module to your "/etc/modprobe.d/blacklist.conf" file or omit compiling of the driver within the kernel.
 * For temporary or per user disabling, add "set bell-style none" or substitute "visual" for "none" within the /etc/inputrc file or the users $HOME/.inputrc file.
 * Other temporary or per user methods include setting the beep length to zero or disabling the bell using setterm and xset utilities.
 * If using GNU Screen, 'CTRL-a CTRL-g'; or adding "vbell off" or "vbell on" within your $HOME/.screenrc; but you'll still have the bell everywhere else unless any of the above are performed.