How can i play a sound (CPU Beep or wav, don't matter what) using the Windows cmd?
Not in windows now, in order to test this possible solution, but try to: "start "
I think it will open the wav file with the associated program that your windows has for ".wav" files.
And note, this is a wild-guess - someone with windows may give you a better solution if this doesn't do the job
You can do this natively with PowerShell. PowerShell is included with Windows Vista and later, and can be downloaded from Microsoft for older versions.
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();
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;
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:
Yes, it's the same as the
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
An alternative method in PowerShell is to use the escape sequence for BEL, rather than inserting a literal BEL character with Ctrl + G:
` 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
^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
Workaround (some sort of):
1) run audio file
2) wait till track ends (in my case its 5 seconds) and close media player
start wmplayer "C:\Windows\Media\Alarm10.wav" && timeout 5 && taskkill /im wmplayer.exe
(While an old thread, people will find it on a search). I see someone has already recommended VLC. I use it to play a sound in Windows without anything visible using parameters: "c:\Program Files (x86)\videolan\vlc\vlc.exe" --qt-start-minimized --play-and-exit "c:\Program Files (x86)\videolan\vlc\Windows Exclamation.wav"
The main addition to the previous comment is --qt-start-minimized The paths and quote characters are just to illustrate a typical use. I've used this unchanged in XP, 7, 10; I expect Vista and 8.x to work too.
If a plain beep is alright, echo the character with the value 7, the so-called bell character. Note, however, that beeps can be turned off.
If you want something else, you'll have to launch an application that does the trick.
You could write a simple console application that took the sound file (or sound id) as an argument and called PlaySound
A very lightweight solution is cmndPlayWAV.jar which also works on Linux and OS/X. It has a built in sound if no parameter is specified or you can give the full path to a .wav file. Incidentally one could always make an audio message .wav to use with Windows Recorder.
On XP I do this
start /min mplay32 /play /close %WINDIR%\media\tada.wav
It's not ideal but it's really easy and it works.
mplayer for this. A bit an overkill as it can play almost any media file. Recent windows builds can be found at spirton, as of 2013. Example usage:
You should add mplayer.exe to your PATH (see What are PATH and other environment variables, and how can I set or use them? or How can I permanently append an entry into the system's PATH variable, via command line? to do this.)
You can use fmedia to play a sound file from Windows terminal:
This command will start the playback of
file.mp3 in foreground and quit after the file has finished playing.
If you wish to do it in background, add
--background switch to your command:
fmedia file.wav --background
This command will start a new process in background and detach from your console immediately.
fmedia is a portable application (works without installation) and consumes very small amount of system resources. Also, its startup time is instantaneous.
P.S. Use command
fmedia.exe --install to add it to your
%PATH% environment variable, otherwise you need to execute it with full path, e.g.