How to emit sound using built-in speaker from a command line?

9

3

How to emit sound using built-in speaker from a command line in Windows and Linux?

Piotr Dobrogost

Posted 2009-07-24T16:07:49.667

Reputation: 4 413

4What operating system? – arathorn – 2009-07-24T16:08:54.500

Answers

10

You can call the Win32 MessageBeep operating system function.

On Windows XP or later, type:

rundll32 user32.dll,MessageBeep

I tried it years ago and at first I didn't believe it would work. But that's Microsoft suggested way, as according to their MSDN website:

"...MessageBeep attempts to play the system default sound. If it cannot play the system default sound, the function produces a standard beep sound through the computer speaker."

GeneQ

Posted 2009-07-24T16:07:49.667

Reputation: 4 581

4

On *nix operating systems beep used to do it.

SYNOPSIS

beep [ -v ] [ -X | -T | -S ]

DESCRIPTION

beep is a command-line utility for making a computer go beep.

Under normal circumstances, you should be able to use it just by typing ‘beep’, with no options.

Jeremy French

Posted 2009-07-24T16:07:49.667

Reputation: 870

What operating systems were these? – Richard Hoskins – 2009-07-24T16:58:06.287

You can install this from most debian based linux repositories with sudo apt-get install beep – Charles Ma – 2009-07-25T05:04:26.117

required modprobe pcspkr too, http://askubuntu.com/questions/19906/beep-in-shell-script-not-working

– Aquarius Power – 2015-11-23T18:44:51.710

2

With bash on Unix:

echo $'\007'

Richard Hoskins

Posted 2009-07-24T16:07:49.667

Reputation: 10 260

1

Echo ^g 

where ^ is the ctrl key. Note this doesn't work on Windows 7 - The beep is redirected to the audio system.

tsilb

Posted 2009-07-24T16:07:49.667

Reputation: 2 492

hey, it works on Windows 7!!!! I think for some motherboards that does not have internal speaker or that it is disabled on sound properties it will not beep. but I tested and functioned!!! but use CTRL instead of "^" character. I don't know the difference, but... – kokbira – 2011-05-10T20:08:52.573