Ubuntu – Turn off Motherboard/PC Speaker “beep” in Ubuntu 16.04 regression

16.04pulseaudiosoundteminal-bellxorg

I see the kernel module pcspkr is blacklisted in Ubuntu 16.04 and indeed when I do a lsmod it doesn't show up. But I still get that annoying loud beep in terminal or GUI editor when pressing or at top of file. Same crazy beep when pressing and when at bottom of file.

I've tried downloading the beep command and overriding pcskr, which presumably is blacklisted anyway, without any effect.

I read about pulseaudio X-11 bell feature and tried to set that up with a nice soft chime sound but no luck there either.

I searched on this topic and the only thing I found was a user who wanted the reverse to turn off wood knock sound and turn on classic beep.

Hopefully others are annoyed by this 1980's style beep and can point me in the right direction. Thanks in advance.

Edit 1

I read through various bug reports this morning but again it seems people want the bell not trying to get rid of it like me.

Found a promising looking directory: ls /usr/share/sounds/ubuntu/stereo/

bell.ogg               desktop-logout.ogg      message-new-instant.ogg     service-login.ogg
button-pressed.ogg     dialog-error.ogg        message.ogg                 service-logout.ogg
button-toggle-off.ogg  dialog-information.ogg  phone-incoming-call.ogg     system-ready.ogg
button-toggle-on.ogg   dialog-question.ogg     phone-outgoing-busy.ogg     window-slide.ogg
desktop-login.ogg      dialog-warning.ogg      phone-outgoing-calling.ogg

Found a nifty program ogg123 that plays music files through the terminal. I think it's installed by default in Ubuntu 16.04.

When you enter: ogg123 /usr/share/sounds/ubuntu/stereo/message.ogg

Audio Device:   PulseAudio Output

Playing: /usr/share/sounds/ubuntu/stereo/message.ogg
Ogg Vorbis stream: 2 channel, 44100 Hz

…you get a pleasant bubble popping sound. Press and change message.ogg to bell.ogg and you get a low bass drum beat (not as pleasant as message.ogg but better than beep). Additionally ogg123 plays the sounds to the default sound device (in my case hdmi TV) instead of the pc speaker. I think it would better if sound played through the device containing the active window that generated the alert though.

From Launcher choosing: System Settings, Sound, Sound Effects looks like this:

Sound Effects

Now the challenge is getting the system sounds already available into the sound effects alert window. Afterwards, according to bug reports there might be a new challenge selecting them and making them behave appropriately.

Edit 2 – Exploring Sounds using GUI method

Using Nautilus it's easier to explore sound directories. Simply click on a sound file and Rhythm Box (the default) will play them. By exploring via GUI, the sub-directory notifications contains more appropriate alerts than the sub-directory stereo. Sample screen below:

GUI Sounds

Best Answer

After much searching I found typing this in the Terminal works:

pactl upload-sample /usr/share/sounds/ubuntu/stereo/message.ogg bell.ogg

It will give a soft bubble popping sound instead of annoying beep. All the other .ogg files can be used from /usr/share/sounds/ubuntu/stereo and /usr/share/sounds/ubuntu/notifications.

The next step is to make it persistent but at least after long hours of searching progress has been made!


Edit 1 - Making it persistent

Internet searches suggest putting:

pactl upload-sample /usr/share/sounds/ubuntu/stereo/message.ogg bell.ogg

into the file ~/.profile but that didn't work. Perhaps pulseaudio wasn't running at that time?

So I ended up putting it in Startup Applications in this screen:

enter image description here

Now it the annoying beeping is gone and a soft bubble popping sound works like a charm in the terminal and gedit.


Edit 2 - Create bash playall, default and menu scripts

Rather than switching directories to select the bell de jour I created a new directory and copied sound candidates from /usr/share/sounds/.../... there:

$ ls /usr/local/bin/bell/sounds
Amsterdam.ogg  Blip.ogg     Mallet.ogg   Positive.ogg  Slick.ogg
bell.ogg       default.ogg  message.ogg  Rhodes.ogg

Next I created a script to sample all sounds in a directory. If a given sound file plays to long you can skip to the end with Ctrl+C.

$cat /usr/local/bin/playall-bells
#! /bin/bash

# NAME: playall-bells
# PATH: /usr/local/bin
# DESC: Play all songs in directory /usr/local/bin/bell/sounds.
#       Parameter 1 can override to different directory.
# CALL: Typically call with "playall-bells" (no parameters).
# DATE: Created Sep 30 2016.

DIRNAME="$1"

# if no parameters set DIRNAME to bell/sounds
if [ $# == 0 ]; then
    DIRNAME=/usr/local/bin/bell/sounds
fi

# Cookie cutter debug section. Remove # from echo's
#echo "********************************************************"
#echo "*                                                      *"
#echo "*  THE DIRECTORY IS: $DIRNAME"
#echo "*                                                      *"
#echo "********************************************************"

for file in $DIRNAME
do
    printf $DIRNAME
    ogg123 $DIRNAME # If a sound plays too long <Ctrl>+C for next
done

A special sound file called default.ogg is used to set the bell sound during boot. To set the default a new script was created.

$cat /usr/local/bin/load-default-bell
#! /bin/bash

# NAME: load-default-bell
# PATH: /usr/local/bin
#      `.ogg` sound files are stored in `/usr/local/bin/bell/sounds`
# DESC: Load bell sound to pulseaudio.
# CALL: Call with "load-default-bell" (no parameters)
#       Does not work in "~/.profile" as some users suggest
#       Works in "Startup Applications" locatable by "Dash"
# DATE: Created Sep 30 2016.
# UPDT: Oct 1 2016 - Play new bell sound after load to pulseaudio.
#       Oct 2 2016 - bell-select-menu has been created to manage default.

# NOTE: Use Nautilus or Terminal Menu to copy desired <sound>.ogg to
#       default.ogg. This sound in turn is uploaded to pulse-audio.
#       New script `bell-select-menu` will update default sound file.
#       Name of the game is to replace annoying motherboard speaker
#       beep which is a regression in Ubuntu 16.04.

pactl upload-sample /usr/local/bin/bell/sounds/default.ogg bell.ogg
printf '\a' # play new bell sound

Coinciding with the new script above the Startup Applications described above was changed to look like this:

Startup Applications Bell

The final step was to create a bash menu to play all sounds, listen to a single sound and update last listened to single sound to the default. The menu design was taken from this askubuntu quesiton: Create bash menu based on file list (map files to numbers). If you like my menu you should go to that question and up-vote that author's answer.

$cat /usr/local/bin/bell-select-menu
#! /bin/bash

# NAME: bell-select-menu
# PATH: /usr/local/bin
# DESC: Present menu of bell sounds to listen to all, listen to one and update default.
# CALL: bell-select-menu
# DATE: Created Oct 1, 2016.

echo "The following /usr/local/bin/bell/sounds were found"

# set the prompt used by select, replacing "#?"
PS3="'a' to hear to all files, use number to hear a single file, 
'u' to update last single file heard as new default, or 'q' to quit: "

lastfile="none"

# allow the user to choose a file
select filename in /usr/local/bin/bell/sounds/*.ogg

do

    # leave the loop if the user types 'q'
    if [[ "$REPLY" == q ]]; then break; fi

    # play all if the user types 'a'
    if [[ "$REPLY" == a ]] 
    then 
        playall-bells
        continue
    fi

    # update last file name as new default if the user types 'u'
    if [[ "$REPLY" == u ]]
    then
        if [[ "$lastfile" == none ]]
        then
            echo "No file was selected."
            break
        fi
        echo "$lastfile selected"
        cp $lastfile /usr/local/bin/bell/sounds/default.ogg
        load-default-bell
        break
    fi

    # complain if no file was selected, and loop to ask again
    if [[ "$filename" == "" ]]
    then
        echo "'$REPLY' is not a valid number"
        continue
    else
        lastfile="$filename"
    fi

    # listen to the selected file
    ogg123 "$filename"

    # loop back to ask for another
    continue
done

The drawback of this design is when you select play all the menu scrolls off the screen and you need to scroll back the window to see the options again.

Phew that's it.