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

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


Solution 1:

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."

Solution 2:

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.