In a bash script/command how can I make a PC beep noise, or play a sound file?

86,045

Solution 1

Try this:

echo ^G

(^G is obtained by ctrl+G).

Note: you can't copy and paste this code in a batch file, it won't work. To obtain a ^G character in a file, type in a cmd window:

echo ^G > beep.txt

(again, ^G is obtained by ctrl+G).

Then you'll have a file named beep.txt, open it with notepad, there will be a square character. This is our ^G once it is saved in a file.

You can then copy and paste it in a batch file to make a sound (don't forget to put "echo" in front of it).

Solution 2

This will make a beep from within bash

echo -en "\007"

Solution 3

spd-say

sleep 2; spd-say 'get back to work'

Infinite loop with -w if you need extra motivation:

sleep 2; while true; do spd-say -w 'get back to work'; done

or if you prefer the carrot:

sleep 2; while true; do spd-say -t female1 -w "I'm done, come back to me, darling"; done

Pre-installed on Ubuntu 14.04 via the package speech-dispatcher: http://releases.ubuntu.com/trusty/ubuntu-14.04.4-desktop-amd64.manifest for blind people I suppose?

See also: https://askubuntu.com/questions/277215/how-to-make-a-sound-once-a-process-is-complete

Also add a popup

This combo is a life saver, b stands for beep:

b() ( spd-say 'done'; zenity --info --text "$(date);$(pwd)" & )

and then:

super-slow-command;b

If I'm somewhere in the room, I'll hear it and know that the long job is done.

Otherwise, I'll see the popup when I get back to my computer.

Related: How to show a GUI message box from a bash script in linux?

Listen to your cooler

I'm joking of course, but for compilation I noticed that I use often use this queue subconsciously. When the cooler stops humming for a while, it means that the compilation is over!

Solution 4

By setting this variable as follows

PROMPT_COMMAND="echo -en '\a'"

then bash will beep every time it shows the prompt. When you do not need it anymore,

unset PROMPT_COMMAND

Solution 5

To play the system sound from Windows command line you can run:

rundll32 user32.dll,MessageBeep

It should work on all version of Windows.

Share:
86,045
scunliffe
Author by

scunliffe

Software Developer. Mainly Web & Mobile Applications. Also an avid AutoCAD user/developer. Twitter: http://twitter.com/scunliffe Blogs: Software Design Blog, Indie Game Dev Blog

Updated on July 08, 2022

Comments

  • scunliffe
    scunliffe almost 2 years

    I have some long running scripts with breaks requiring input/interaction to continue but when I switch to another window I'd like to be notified (by sound) that a task is complete and now awaiting input.

    I would prefer to be able to play an audio clip (*.mp3, *.ogg, etc.) but wouldn't care if the only solution is to make the PC Speaker beep noise.

    Any ideas? I'm open to any CLI utilities I can install that play sounds that in turn I can execute when needed.

    FYI: My System is running WinXP Pro.

    UPDATE: Doh! My Windows > Control Panel > Sounds > Default Beep: was set to (none). Grrr...

    Problem solved.