#1 20 Dec 2019 02:16

Rekrul
Member
Registered: 17 Apr 2016
Posts: 69

Fastest way to play a sound file from the command line?

What is the simplest and fastest way to play a sound file from the command line?

So far all the solutions I've found either involve calling a full-blown media player or using a Swiss Army Knife type program that also performs about 100+ other functions besides playing sound files.

I was hoping there would be a single-purpose command line program just for playing a sound file, but such a program doesn't seem to exist.

The reason I'm unhappy with the existing programs is that I'd like to play several sound files in quick succession and all the ones I've tried (sndrec32.exe, wizmo.exe, etc) introduce a short delay between the sounds. I assume that's because they load into memory, run, then unload from memory each time.

I'd like the sounds to play one after the other as quickly as possible.

Ideally I'd like a program that I could feed a list of sound files to and it would play them all, but a program that can run quickly from the command line to play one sound file would be great too.

Offline

#2 20 Dec 2019 10:14

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 1,061
Website

Re: Fastest way to play a sound file from the command line?

I havent actually tried this, but Winamp playlists are just a text file of paths to the mp3 files, so you could generate a playlist and then open that in a minimised copy of Winamp (or any other player which can use the same playlist format)

Offline

#3 22 Dec 2019 03:59

Rekrul
Member
Registered: 17 Apr 2016
Posts: 69

Re: Fastest way to play a sound file from the command line?

Simon Sheppard wrote:

I havent actually tried this, but Winamp playlists are just a text file of paths to the mp3 files, so you could generate a playlist and then open that in a minimised copy of Winamp (or any other player which can use the same playlist format)

Unfortunately that would still introduce a significant delay when first called as the program would have to be loaded into memory. I'm looking for something where the sound plays as close to instantly as possible when the command is issued.

Offline

#4 22 Dec 2019 13:14

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 1,061
Website

Re: Fastest way to play a sound file from the command line?

The old version of WinAmp (2.95) is very small and will I think load as fast if not faster than sndrec32.exe
http://www.oldversion.com/windows/winamp/

Offline

#5 04 Jan 2020 19:46

pappaG
Member
Registered: 04 Jan 2020
Posts: 3

Re: Fastest way to play a sound file from the command line?

Rekrul
One that I use is Nircmd v2.86, you can do a search, I use it to play text from a file, play one second of a mp3 or play from the clipboard.
It does have a small delay but not much

Offline

#6 21 Mar 2020 17:44

anic17
New Member
Registered: 21 Mar 2020
Posts: 1

Re: Fastest way to play a sound file from the command line?

I don't know if this can be done in pure batch without external programs, but I know to make it in VBScript

Set oPlayer = CreateObject("WMPlayer.OCX")

'Sound path
oPlayer.URL = "C:\Music\MySound.wav"

'Play the music
oPlayer.controls.play 
While oPlayer.playState <> 1 ' 1 = Stopped
  WScript.Sleep 100
Wend
oPlayer.close

So the code will be

echo Set oPlayer = CreateObject("WMPlayer.OCX") > "%TMP%\Sound.vbs"

echo 'Sound path >> "%TMP%\Sound.vbs"
echo oPlayer.URL = "C:\Music\MySound.wav" >> "%TMP%\Sound.vbs"

echo 'Play the music >> "%TMP%\Sound.vbs"
echo oPlayer.controls.play >> "%TMP%\Sound.vbs"

echo While oPlayer.playState <> 1 ' 1 = Stopped >> "%TMP%\Sound.vbs"
echo   WScript.Sleep 100 >> "%TMP%\Sound.vbs"
echo Wend >> "%TMP%\Sound.vbs"

echo 'Close >> "%TMP%\Sound.vbs"
echo oPlayer.close >> "%TMP%\Sound.vbs"
start /wait WScript.exe "%TMP%\Sound.vbs"

When the script ends before an EXIT simply put

DEL "%TMP%\Sound.vbs" /Q /F>NUL

It has a small delay

I wish that this code could you help smile

Offline

Board footer

Powered by FluxBB