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: 6031
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: 177
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: 6031
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: 177
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: 6031
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?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

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

#23 Post by Ed Dyreen » 29 Jan 2019 09:12

jer wrote:My interest in this was to find a solution to quickly and rapidly play mechanical or electronic typing sounds
from a small wav file or files, each file having only one typewriter keystroke or carriage return sound. htaplayer
would not be a good fit for this, and the best I could come up with is the DOS beep sound.
I've since moved on to the next 'big project'.
Jerry
This is a late response the OP probably won't read but...

Response time depends on the size of the program, the size of the file played and I haven't seen any program that would play audio without hardware support if drivers are installed. But even generic drivers should work.

You should convert your wav files to mp3 so they will load quicker. when you convert wav to mp3 frequencies that are not audible to most people are cut of which results in a smaller file. So by converting wav to mp3 you loose information, that is why it doesn't make sense to convert an mp3 to wav. those frequencies will be filled with zero's and then do nothing but increase the file size. wav is uncompressed full range audio.

There are certain sounds that the human ear cannot hear.
There are certain sounds that the human ear hears much better than others.
If there are two sounds playing simultaneously, we hear the louder one but cannot hear the softer one.

Using facts like these, certain parts of a song can be eliminated without significantly hurting the quality of the song for the listener. Compressing the rest of the song with well-known compression techniques shrinks the song considerably -- by a factor of 10 at least. When you're done creating an MP3 file, what you have is a "near-quality" song. The MP3 version of the song does not sound exactly the same as the original song because some of it has been removed.

madPlay is specifically designed to be run from batch so it is small and it handles mp3 files and it's free and easy in use.
You can find it on the internet or download my binaries.

kwsiebert
Posts: 42
Joined: 20 Jan 2016 15:46

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

#24 Post by kwsiebert » 29 Jan 2019 09:44

Ed Dyreen wrote:
29 Jan 2019 09:12
You should convert your wav files to mp3 so they will load quicker. when you convert wav to mp3 frequencies that are not audible to most people are cut of which results in a smaller file. So by converting wav to mp3 you loose information, that is why it doesn't make sense to convert an mp3 to wav. those frequencies will be filled with zero's and then do nothing but increase the file size. wav is uncompressed full range audio.
Is this a normal behavior for all encoders? I haven't looked deeply into audio encodings, but this is the first time I've heard this mentioned.

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

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

#25 Post by ShadowThief » 29 Jan 2019 20:30

kwsiebert wrote:
29 Jan 2019 09:44
Ed Dyreen wrote:
29 Jan 2019 09:12
You should convert your wav files to mp3 so they will load quicker. when you convert wav to mp3 frequencies that are not audible to most people are cut of which results in a smaller file. So by converting wav to mp3 you loose information, that is why it doesn't make sense to convert an mp3 to wav. those frequencies will be filled with zero's and then do nothing but increase the file size. wav is uncompressed full range audio.
Is this a normal behavior for all encoders? I haven't looked deeply into audio encodings, but this is the first time I've heard this mentioned.
Not all encoders, but all lossy encoders. If you convert from WAV to a lossless format like FLAC, you'll get the same sound.

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

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

#26 Post by penpen » 01 Feb 2019 04:37

OctavioShaffer wrote:
09 Jan 2019 16:32
how to install that that player?
Just download the wav player from the link given by foxidrive in that post:
viewtopic.php?f=3&t=6917#p44953.

Then unpack the compressed (zip) file into a directory of your choice and it is ready to be used.

To uninstall that program just delete it.
OctavioShaffer wrote:
09 Jan 2019 16:32
How is it works?
All neccessary is described within "wv_player.txt".
OctavioShaffer wrote:
09 Jan 2019 16:32
Is this player have not affect on my computer if I install that app?
I'm unsure what you might mean?
It has the affect that you can play wav files (and other media files, if the needed drivers are installed).
It shouldn't have any bad effect, but because this isn't my program i can't say that for sure.
If you don't trust it, you might want to test that program on a virtual PC (which isn't run on your main pc) first, then on a secondary non virtual PC.
Basing on the test results you may (or may not) use that program.

Ed Dyreen wrote:
29 Jan 2019 09:12
Response time depends on the size of the program, the size of the file played
It also depends on the compression algorithm used to reduce the resulting filesize (although most decompressions only need the computational power of a 386er...).
Ed Dyreen wrote:
29 Jan 2019 09:12
wav is uncompressed full range audio.
That's not fully true.
The "wav" file extensions referrs to the RIFF WAVE container format that may or may not contain uncompressed data:
It may also already contain mp3 compressed data.

Some coding schemes are mentioned here:
https://en.wikipedia.org/wiki/WAV#Compa ... ng_schemes.

Although i must admit in many cases wav just contains LPCM data and therefore is uncompressed - you can't be sure,
so you better should check the result on quality and size.


penpen

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

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

#27 Post by Ed Dyreen » 01 Feb 2019 17:49

penpen wrote:
01 Feb 2019 04:37
It also depends on the compression algorithm used to reduce the resulting filesize (although most decompressions only need the computational power of a 386er...).
Hey, not too rough !

It takes a 386sx 4MBram 33Mhz (1982 ) little processing power to play a wav, unless you had a sound-card that did not support it by hardware. which would be odd because it's not compressed normally.

wav format is actually what is written on standard cd audio, via a cable you could plug in directly to the sound card and then the cd would be able to play digital wav audio without the main cpu involved.

I'm too young to die !

Hurt me plenty, Ultra-Violence Nightmare! :mrgreen:

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

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

#28 Post by penpen » 01 Feb 2019 19:37

Ed Dyreen wrote:
01 Feb 2019 17:49
It takes a 386sx 4MBram 33Mhz (1982 ) little processing power to play a wav, unless you had a sound-card that did not support it by hardware. which would be odd because it's not compressed normally.
I agree on wav-files that contain uncompressed LPCM data at 44,100 Hz.
If a wav-file contains a 160 Kbps mp3 and you have no hardware support for mp3, then it surely will take a 486 (or better) to play that data in real time.
Ed Dyreen wrote:
01 Feb 2019 17:49
wav format is actually what is written on standard cd audio
No, a standard Audio CDs is encoded in "Red Book audio" which is two-channel signed 16-bit Linear PCM data sampled at 44,100 Hz and are optionally pre-emphasised (to reduce noise which increasingly occurs on high frequencies).

As said before the wav-container might or might not contain 16 bit LPCM data at 44,100 Hz.
As far as i know no encoding that can (actually) be stored in a wav-file does support pre-emphasis; so if you rip a CD mastered with pre-emphasis you have to compute the de-emphasised signal, else if playing the rawdata (stored in a file with wav-extension) the resulting music would sound... interesting.

Some example CDs could be found here:
http://www.studio-nibble.com/cd/index.p ... ease_list)

(Somehow i am tempted to search my Final DOOM CD in one of my packing cases and play it... :D .)


penpen

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

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

#29 Post by Ed Dyreen » 07 Feb 2019 20:35

ok let's be punctual,

If the wav is pcm encoded, then it is a proper input format for standard audio CD and burning .CDA tracks. No CPU is involved when an analog audio cable is connected to the cd-drive playing the CD in analog mode.
penpen wrote:
01 Feb 2019 19:37
(Somehow i am tempted to search my Final DOOM CD in one of my packing cases and play it... :D .)
I have it running on my 386sx :)

Post Reply