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



Question:

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.


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

copy con beep.bat [Enter]

@echo off [Enter]

echo [Ctrl+G] [Enter]

[Ctrl+Z] [Enter]

beep.bat [Enter]


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

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  

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

Also add a popup

This combo is a life saver:

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?


Solution:6

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

rundll32 user32.dll,MessageBeep  

It should work on all version of Windows.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »