Play a sound (maybe WAV?) from Windows line command

You can do this natively with PowerShell. PowerShell is included with Windows Vista and later, and can be downloaded from Microsoft for older versions.


Wave files

PowerShell can be used to load the System.Media.SoundPlayer .NET class, which can be used to play a wave file.

(New-Object Media.SoundPlayer "C:\WINDOWS\Media\notify.wav").Play();

If you want, you can run this from the normal command line:

powershell -c (New-Object Media.SoundPlayer "C:\Windows\Media\notify.wav").PlaySync();

(note that PlaySync is used in the second example since the standard asynchronous play would be interrupted by the PowerShell process closing when launched like this)

And if you wanted to play only the first, say, 5 seconds of the sound:

powershell -c (New-Object Media.SoundPlayer "C:\Windows\Media\notify.wav").Play(); Start-Sleep -s 5; Exit;

Beep

A beep can be easily accomplished in the normal command line with echo ^G (where ^G represents BEL, ASCII character 7, inserted with Ctrl + G), as described in other answers. In the interest of completeness, here's the PowerShell method:

echo ^G

Yes, it's the same as the cmd one. echo in PowerShell is an alias (i.e. means the same thing) to Write-Host, which displays something to the screen (or triggers the Windows notification sound in the case of BEL).

An alternative method in PowerShell is to use the escape sequence for BEL, rather than inserting a literal BEL character with Ctrl + G:

echo `a

` is PowerShell's escape character, which modifies the meaning of the character after it. An escaped a indicates BEL. The advantage of this approach is it is easier and more visible when typed into a script.

To run this in a batch file (again, Vista or later):

powershell -c echo `a

source


echo ^G

Where ^G is CTRL + G or Alt + 7 on the keypad.


Install VLC. Use the following command. It starts up REALLY fast. This is what I used on Windows 7 b/c wmplayer takes so long to load, and the /close option was removed from wmplayer.

vlc.exe --play-and-exit audio.wav