Short WAV files-is there no standard player to call from batch?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Short WAV files-is there no standard player to call from batch?

#16 Post by foxidrive » 21 Mar 2016 12:08

Jer wrote:foxidrive, swavplayer did not play a wav file of 4,458 bytes.

a file called sounder.exe that plays 2 seconds of a wav file.

My OS is Windows 7 32-bit.


They both play a tiny wav file here in Windows 8.1 and XP Pro, and a 7 second file plays too.

Try playing your file with Windows Media player, it will probably play it, but VLC might not. I found that here.

Wav files have all sorts of internal variations in codec and sample rate etc. Have you examined that aspect?

The tiny file is attached here.

Code: Select all

@echo off
if not exist "menu2.wav" (
echo creating "menu2.wav"
(
echo UklGRhsBAABXQVZFZm10IBAAAAABAAEAESsAABErAAABAAgAZGF0YfcAAABcW1tc
echo XF1eX2BjZGhsdIO1/////70gAAAAS6no/9KcaT81THGVrK2fh3BpbXaDk5KOipCr
echo wMe7kmRANlWOzPHnvINUQU92osPNvaB+ZFhabYeitrqulnlfVFx3mLK7r5V5ZV9m
echo dYeWoKKcjXtqYWRzhpifm45+cWlmanN+iI+Ph3lrYV9lcHuBg4F8dGphXV9oc32A
echo fnZuZmFfX2Rqc3h5dW1lX15fY2ZrcHR0b2ljX19hZWltcHFwbWdjYGFkaGtvcXJx
echo b2pmZGVpbXBzdHV0cW1qam1wdHd5e3t6d3RzdHZ5fH6AgYB+fHl5e31+gYOFhYOC
echo gICA
)>"decode.tmp"
certutil /decode /f "decode.tmp" "menu2.wav" >nul
del "decode.tmp"
)



Code: Select all

General
Format                         : Wave
File size                      : 291 Bytes
Duration                       : 22ms
Overall bit rate mode          : Constant
Overall bit rate               : 106 Kbps

Audio
Format                         : PCM
Format settings, Endianness    : Little
Format settings, Sign          : Unsigned
Codec ID                       : 1
Duration                       : 22ms
Bit rate mode                  : Constant
Bit rate                       : 88.2 Kbps
Channel(s)                     : 1 channel
Sampling rate                  : 11.025 KHz
Bit depth                      : 8 bits
Stream size                    : 247 Bytes (85%)


Jer
Posts: 146
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Short WAV files-is there no standard player to call from batch?

#17 Post by Jer » 22 Mar 2016 09:24

Windows Media Player plays does play the short wav files.
The issue was about the time it takes for WMP to load on a
slower PC, which made the ghost typer demo with sound
not workable on slower computers.

I do not know what to do with your attachment except run it as a
batch file and I got this:
'"menu2.wav.encoded.bat"' is not recognized as an internal or external command,
operable program or batch file.
Could Not Find C:\Temp\DOSBatch\menu2.wav.encoded.bat

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Short WAV files-is there no standard player to call from batch?

#18 Post by foxidrive » 22 Mar 2016 17:24

Jer wrote:The issue was about the time it takes for WMP to load on a
slower PC, which made the ghost typer demo with sound
not workable on slower computers.


What speed is the machine - are you testing it with Windows 7 as you mentioned?

I do not know what to do with your attachment except run it as a
batch file and I got this:
'"menu2.wav.encoded.bat"' is not recognized as an internal or external command,
operable program or batch file.
Could Not Find C:\Temp\DOSBatch\menu2.wav.encoded.bat


Thanks for pointing that out Jer.

It created the menu2.wav file but the last two commands were a copy-and-paste error that aren't supposed to be there. My code is a mess to read so I edited it in the post above and improved it.

Jer
Posts: 146
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Short WAV files-is there no standard player to call from batch?

#19 Post by Jer » 24 Mar 2016 10:14

My laptop specs: Processor Intel(R) Core(TM) i7-2670QM CPU @ 2.20GHz, 2201 Mhz, 4 Core(s), 8 Logical Processor(s)
Your very small wav file with a popping sound plays well. I never had a problem with laptop speed and the ghost typer.
When I ran the same code on the Pentium 4 PC, it performed poorly, and it seemed obvious that any wav player I tried
could not keep up with the rapid calls to play the keystroke sounds. That put a damper on the idea of sharing ghost typer
with wav file sounds because those with slower computers would find it unworkable.

Thanks for fixing the menu2.wav code. Is that file-creation process too complex to teach how it is done?

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Short WAV files-is there no standard player to call from batch?

#20 Post by foxidrive » 24 Mar 2016 16:46

Jer wrote:When I ran the same code on the Pentium 4 PC, it performed poorly, and it seemed obvious that any wav player I tried could not keep up with the rapid calls to play the keystroke sounds.

It's been so many years since my P4 days - I wonder if the P4's poor response is audio driver related? It wouldn't be using a software audio codec, would it?

Sharing the code still seems a fair thing - there wouldn't be too many P4 machines still in use as main PCs...
Is that file-creation process too complex to teach how it is done?


To create the encoded version of the file, a command using certutil is used:
certutil /encode /f "yourfile.wav" "encode.tmp"

Another certutil command recreates the original file from the encode.tmp file
certutil /decode /f "encode.tmp" "yourfile.wav"


The batch code I jigged up below assembles the lines from the encoded.tmp file into some lines of batch script that you can paste into your own code. You can paste several in a row, from different wav files, and when your batch file runs it will re-create the wav file if they don't already exist.

There are other methods created by the guys at dostips that use compression etc to create smaller lines of code. Certutil isn't available on XP.


Code: Select all

@echo off
set suffix=create.bat
if "%~1"=="" (
  echo( Syntax: "%~0" "filename.mp3"
  echo( to encode the filename.mp3 into a filename.%suffix% batch script
  echo( - any filetype can be encoded into a batch script, even another .bat file
  echo(
  pause & goto :EOF
  )
echo(creating "%~n1.%suffix%"
certutil /encode /f "%~1" "encode.tmp"
find /v /i "CERTIFICATE---" <"encode.tmp" >"encode.tm"
(
echo @echo off
echo if not exist "%~nx1" (
echo echo creating "%~nx1"
echo (
for /f "usebackq delims=" %%a in ("encode.tm") do echo echo %%a
echo ^)^>"decode.tmp"
echo certutil /decode /f "decode.tmp" "%~nx1" ^>nul
echo del "decode.tmp"
echo ^)
)>"%~n1.%suffix%"
del "encode.tm*"

sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Re: Short WAV files-is there no standard player to call from batch?

#21 Post by sambul35 » 22 May 2016 20:00

Jer wrote:Is there any hope in this world for a common un-bloated wav file player (running from a batch with no GUI)?
:cry:

I was looking for this very answer for a Win 10 64-bit PC, since many older players and echo ^G bell won't run from a batch on it, and I wanted to be able to start a batch with args using a keyboard shortcut with PC monitor switched off, so the only hint of the batch start would be a Windows sound accord through a default speaker. "Un-bloated" in my book means 1-to-4 lines of batch code with fast native implementation. You'll be surprised, it exists, by calling the Powershell commands below from a batch to invoke .Net Framework System.Media classes to play a wav. :D Not sure if this method can play other audio formats as well, just replace the path to your sound file and let us know.

Code: Select all

:: To play any wav from a batch, add this command to it with path to your wav file
powershell -c "(New-Object Media.SoundPlayer "C:\Windows\Media\notify.wav").PlaySync();"

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

:: play Bell sound
powershell -c echo `a

:: play default system sounds (substitute Asterisk with Beep, Exclamation, Hand, Question)
powershell -c "[System.Media.SystemSounds]::Asterisk.Play();"

Alternatively, you can call from your batch Sounds.vbs script below to play any wav (I tested on Win 10), or create a combo batch & VBS script instead of using standalone audio players:

Code: Select all

cscript "K:\Media\Sounds.vbs" "C:\Windows\Media\Windows Logon.wav"

On a side note (though its not required to play wav files from a batch), to manually start a batch on a PC with display switched off, if logged out you need to logon to Windows first. In Win 10 the default Logon, Logoff and other related sounds are blocked. To make sure the blind logon was successful, one can add a scheduled task in Task Scheduler to play a wav sound at logon - it can be a similar batch or VBS script:

on event 7001 - run a VBS script with a "sound file path" argument
WScript.exe "K:\Media\Sounds.vbs" "C:\Windows\Media\Windows Logon.wav"

Code: Select all

:' Content of Sounds.vbs
Set args = WScript.Arguments
SoundFilePath = args.Item(0)

Set oVoice = CreateObject("SAPI.SpVoice")
set oSpFileStream = CreateObject("SAPI.SpFileStream")
oSpFileStream.Open SoundFilePath
oVoice.SpeakStream oSpFileStream
oSpFileStream.Close

OctavioShaffer
Posts: 1
Joined: 09 Jan 2019 16:10

Re: Short WAV files-is there no standard player to call from batch?

#22 Post by OctavioShaffer » 09 Jan 2019 16:32

Hello! Can I ask about WAV player? how to install that that player? I have been used an android app, that can be able for streaming and featuring but my computer gets slow and always lag. That's why I want to try WAV player. How is it works? Is this player have not affect on my computer if I install that app?

Post Reply