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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Jer
Posts: 155
Joined: 23 Nov 2014 17:13
Location: California USA

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

#1 Post by Jer » 22 Jan 2016 12:41

Foxidrive's ghost typer with added wav file mechanical typewriter sounds for each
ASCII character displayed, plus a carriage return sound at the appropriate times
performs very well on my Win 7 laptop. With Winamp as the default wav file player,
there is no perceptible delay between character visibility and the keystroke sound.

When the same batch file is run on the slower Pentium 4 PC, (Win 7),
performance is annoying and unacceptable; that includes testing with
Winamp and Windows Media Player. I assume it takes too long for these
applications to open on the slower PC.

Is there any hope in this world for a common un-bloated wav file player?
:cry:

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

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

#2 Post by foxidrive » 22 Jan 2016 12:57

I like the concept you've described when using sounds with the player. :)

http://www.free-downloads-center.com/do ... 89895.html

I've used that in the past and it's a useful little tool. I even donated to the guy.
Wav Player is a Freeware released by Jose Falcao.

Squashman
Expert
Posts: 4114
Joined: 23 Dec 2011 13:59

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

#3 Post by Squashman » 22 Jan 2016 12:58

In Windows XP, Sound Recorder was the default program for play and recording WAV files. Doesn't seem to do that anymore in Windows 7.

npocmaka_
Posts: 481
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

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

#4 Post by npocmaka_ » 23 Jan 2016 02:56

There more than enough ways to play sounds with the windows built-in tools.
For pure command line player probably I'll prefer SpVoiceobjects - as it is is rich on options. Here's a script that use this and you can use it like:

Code: Select all

spplayer.bat "C:\Windows\Media\Ring05.wav"




you can also use windows media player object or even internet explorer embed tag:


Code: Select all

<!-- :
@echo off
start "" mshta.exe "%~f0"
exit /b
-->

<HTA:Application
   ShowInTaskbar = no
   WindowsState=Minimize
   SysMenu=No
   ShowInTaskbar=No
   Caption=No
   Border=Thin
>
<meta http-equiv="x-ua-compatible" content="ie=edge" />

<html>
<script language="javascript" type="text/javascript">
    window.visible=false;
    window.resizeTo(1,1);
</script>
<embed src="C:/Windows/Media/Ring05.wav" autostart='true' width=1 height=1 id="wavfile" enablejavascript="true">
</html>

Meerkat
Posts: 81
Joined: 19 Jul 2015 02:27
Location: Philippines

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

#5 Post by Meerkat » 23 Jan 2016 07:19

npocmaka_ wrote:you can also use windows media player object or even internet explorer embed tag:

Code: Select all

<!-- :
@echo off
start "" mshta.exe "%~f0"
exit /b
-->

<HTA:Application
   ShowInTaskbar = no
   WindowsState=Minimize
   SysMenu=No
   ShowInTaskbar=No
   Caption=No
   Border=Thin
>
<meta http-equiv="x-ua-compatible" content="ie=edge" />

<html>
<script language="javascript" type="text/javascript">
    window.visible=false;
    window.resizeTo(1,1);
</script>
<embed src="C:/Windows/Media/Ring05.wav" autostart='true' width=1 height=1 id="wavfile" enablejavascript="true">
</html>


I see the HTA window, and it did not close... Btw, other scripts are very nice. Does spplayer.bat also play other media files like MP3, etc?

Meerkat

npocmaka_
Posts: 481
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

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

#6 Post by npocmaka_ » 23 Jan 2016 16:57

SpVoice is only for wav files I think.


With windows media player you can play anything.

With jscript.net/batch hybrid also WMPLib.WindowsMediaPlayer and System.Media.SoundPlayer(again only for WAV) van be used.

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

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

#7 Post by Jer » 23 Jan 2016 21:30

Maybe this is an idea whose time has not come yet: in a batch script calling an application repeatedly to
rapidly play a short wav file to mimic mechanical keystrokes as the character appears on the screen,
and not being too slow to appreciate the affect.

spplayer.bat plays the larger wav file which has 8,718 bytes, but not the smaller keystroke-sound
file that has 4,558 bytes (sound is not audible). The delay is noticeably longer using spplayer.bat

I sent an email to Jose Falcao to ask if he might know why the smaller wav file is silent when
played with his wav player application.

If there is a way to post the two wav files, let me know how and I will include them.

edit 1/25/16 Sent another email to Jose Falcao saying that increasing the file size, which I did
by adding silence to the end, made the previously silent file audible. I will add another reply after
further development and testing. Jose's wv_player application does open and close rapidly and
does the job.

Code: Select all

@:Ghost Typer test.
@:Goodbye.


:: Add text above and start each line with @:
:: Do not use " in the text, replace them with '

@echo off
:: Ghost typer II rev.

:: Adjust speed variable - higher numbers increase typing speed - default=3
set speed=10

for /f "tokens=1,* delims=:@" %%a in ('findstr /n "^@:" "%~f0" ') do (
    set "line-%%a=%%b"
    if "%%b"=="" set "line-%%a= "
    set "numlines=%%a"
)

for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"

for /L %%a in (1,1,%numlines%) do set num=0&call set "line=%%line-%%a%%"&call :type

pause
goto :EOF

:type
call set "letter=%%line:~%num%,1%%"
set "delay=%random%%random%%random%%random%%random%%random%%random%"
set "delay=%delay:~-6%"
if not "%letter%"=="" (
   set /p "=a%bs%%letter%" <nul
   if not "%letter%"==" " call spplayer.bat twtype.wav
)

for /L %%b in (1,%speed%,%delay%) do rem
if "%letter%"=="" echo.&call spplayer.bat twreturn.wav&goto :EOF
set /a num+=1
goto :type
Last edited by Jer on 25 Jan 2016 20:30, edited 1 time in total.

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

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

#8 Post by foxidrive » 24 Jan 2016 00:14

Jer wrote:spplayer.bat plays the larger wav file which has 8,718 bytes, but not the smaller keystroke-sound
file that has 4,558 bytes (sound is not audible).


My suspicion is that the wav encoding format is odd - convert both files to MP3 and try it.

If that solves it then converting the wav file again - to wav but making the encoding options normal - should also fix it.

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

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

#9 Post by Jer » 04 Feb 2016 23:11

Attempts to add a wav file sound after each character is displayed by the Ghost Typer
did well on my laptop (i7, 2.20 Ghz, Windows 7 32-bit) but ran extremely slow when tested
on the Pentium 4 PC (Windows 7 & XP), even using wv_player.exe and spplayer.bat to play the wav file.
That batch code would be a waste of time to try on a slower computer, so I am not posting the code.

The batch hybrid code below uses the computer beep (ASCII 07) and performs reasonably well if you choose
the right delay settings in milliseconds. You are required to edit the two variables delayMin and delayMax to
change delay settings. If you choose, for example, minDelay=200 and maxDelay=500,
you should see a noticeable variation as a random delay period between 200 and 500 is calculated for each character.

1 millisecond min and max delay trips up the delay/sound synchronization, while 100 or more milliseconds improves the sound effect.

You can also run the batch file without sound by adding the F flag (F as in False) i.e., batch_filename F
Without sound, set both delay settings to 1, and then experiment with higher values if the text zips by too fast.

Credit to this forum’s moderators ; you should recognize your code and methods in this batch file.
Jerry

Code: Select all

@:[Dave] HAL, do you read me?
@:
@:[HAL] Affirmative Dave, I read you.
@:
@:[Dave] Open the pod bay doors HAL.
@:
@:[HAL] I'm sorry Dave. I'm affraid I can't do that.
@
<!-- : Begin batch script

:: Add text above and start each line with @:
:: Do not use " in the text, replace them with '
::
:: Alternate usage:  batch_filename F   (run without sound)
::

@echo off
:: Ghost typer II rev.
setlocal

rem edit the following 2 lines. default delay between characters is 100 milliseconds.
Set /A delayMin=100
Set /A delayMax=400

If /I "%1"=="F" (Set "soundOption=F") Else Set "soundOption=T"

For /f "tokens=1,* delims=:@" %%a In ('findstr /n "^@:" "%~f0" ') Do (
    Set "line-%%a=%%b"
    If "%%b"=="" Set "line-%%a= "
    Set "numlines=%%a"
)

If /I "%soundOption:~0,1%"=="T" (Set "soundOption=T") Else Set "soundOption=F"

If "%soundOption%"=="T" Call :charConvert "07" "beep"
Call :charConvert "08" "BS"
If EXIST temp_.vbs DEL temp_.vbs

For /L %%a In (1,1,%numlines%) Do Set num=0&Call Set "line=%%line-%%a%%"&Call :type
pause

endlocal & GoTo:eof

:: ________________________functions begin here________________________

:type
 Call Set "letter=%%line:~%num%,1%%"
 If not "%letter%"=="" Set /p "=a%bs%%letter%" <nul& rem display character or space

 Call:funcRand "%delayMin%" "%delayMax%" dev

 If not "%letter%"=="" If not "%letter%"==" " (
    cscript //nologo "%~f0?.wsf" "beep" "%dev%" "%soundOption%"
 ) Else If "%letter%"==" " (
    cscript //nologo "%~f0?.wsf" "nobeep" "%dev%" "%soundOption%"
 )

 Set /A num+=1
 If "%letter%"=="" (
    Echo(
    cscript //nologo "%~f0?.wsf" "nobeep" "300" "%soundOption%"& rem pause between lines
    GoTo:eof
 )

 GoTo :type
:: *  *  *  *  *  *  *  *  end type function *  *  *  *  *  *  *  *


:funcRand
 rem calculate milliseconds delay within a range if two positive numbers were provided.
 setlocal EnableDelayedExpansion

 Set /A delayDefault=100
 If %~1 equ 0 Set /A num=%delayDefault%& GoTo:endRand

 Set /A varMin=%~1 - 1
 Set /A varMax=%~2
 Set /A varScope=%varMax%-%varMin%

 If not %varMin% geq 0 Set /A num=%delayDefault%& GoTo:endRand
 If not %varMax% gtr 0 Set /A num=%delayDefault%& GoTo:endRand

 Set "Rand(x)=( (x)*!random!/32768+1 )"
 Set /A num=%Rand(x):x=!varScope!% + %varMin%

 :endRand
 endlocal & set "%~3=%num%"& exit /b
:: *  *  *  *  *  *  *  *  end funcRand function *  *  *  *  *  *  *  *


:charConvert
 rem assign ASCII character from decimal in %1 to variable name in %2
 rem which would be the BEL character (ASCII 07) or backspace (08)
 setlocal
 Set "charDecimal=%~1"

 Echo Dim fso, objStream, chrTemp, dest>temp_.vbs
 Echo dest="chartemp.txt">>temp_.vbs
 Echo Set fso = CreateObject(^"Scripting.FileSystemObject^")>>temp_.vbs
 Echo Set objStream = fso.CreateTextFile(dest, True, False)>>temp_.vbs
 Echo chrTemp ^= ^"_^" + Chr(WScript.Arguments.Item(0)) + ^"_^">>temp_.vbs
 Echo objStream.writeline chrTemp>>temp_.vbs
 Echo objStream.close>>temp_.vbs

 WScript.exe temp_.vbs %charDecimal%
 Set /p spclASCII=<chartemp.txt
 Set "spclASCII=%spclASCII:~1,1%"
 If EXIST chartemp.txt DEL chartemp.txt

 endlocal & set "%~2=%spclASCII%"& exit /b


----- Begin wsf script --->

<job><script language="VBScript">

Set args=Wscript.Arguments
If args(0) = "beep" And args(2) = "T" Then WScript.StdOut.Write Chr(7)
WScript.Sleep Args(1)

</script></job>


npocmaka_
Posts: 481
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

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

#10 Post by npocmaka_ » 16 Mar 2016 17:43

Turns out that HTA/Internet explorer is capable of playing MP3/Wav/... files.

But it is a little bit complicated.

IE 10 and 11 are trying to be HTML5 compatible - as a side effect HTA:Application tags will not work when the installed browser is higher than IE 9 by default . So they have <embedded> and <sound> tags . But both are a little bit buggy.

Sound tag will not work with a lot of file formats - https://connect.microsoft.com/IE/feedba ... lid-source.
And embed cannot handle 'onended' event.

And worse window.visible=false; will not work because of attempted html5 compatibility.

But surprise - there's a non-standard bgsound available only for internet explorer. And it can play a lot of sound file formats (I suppose even without installed media player) !
Even sound volume can be set ! The values are between -10000 and 0 where the 0 is the loudest.
The most difficult with bgsound is to decide when to close the script. I've used shell.application GetDetailsOf() function. I've also used window.setTimeout() and I'm not sure if this will work for IE 8 and 7 (and 6?) as it is relatively new standard function.


Example:

Code: Select all

htaPlayer.bat "C:\Windows\Media\Ring05.wav" -1000


Here's the-ultimate batch sound player:


Code: Select all

<!-- :
@echo off
(echo(%*)|mshta.exe "%~f0"|findstr "^"
exit /b
-->

<HTA:Application
   WindowsState=Minimize
   SysMenu=No
   ShowInTaskbar=no
   Caption=No
   Border=Thin
   ID="player"
>
<meta http-equiv="x-ua-compatible" content="ie=9" />

<html>
<bgsound src="" volume=''>
<body>




<script language="javascript" type="text/javascript">
window.visible=false;
window.resizeTo(0,0);

var output= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);
var input= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(0);
FSOObj = new ActiveXObject("Scripting.FileSystemObject");
var objShell=new ActiveXObject("Shell.Application");

var lenMagicNumber=27;
var volume=0;
var file='';
var seconds=0;
var start=0;

var arguments=input.ReadLine().trim();


function lenToSeconds(len){
   var hhmmss=len.split(":");
   return Number(hhmmss[0])*3600 + Number(hhmmss[1])*60 + Number(hhmmss[2]);
}

//fso
existsFile = function (path) {
   return FSOObj.FileExists(path);
}

getFullPath = function (path) {
    return FSOObj.GetAbsolutePathName(path);
}

//paths
getParent = function(path){
   var splitted=path.split("\\");
   var result="";
   for (var s=0;s<splitted.length-1;s++){
      if (s==0) {
         result=splitted[s];
      } else {
         result=result+"\\"+splitted[s];
      }
   }
   return result;
}


getName = function(path){
   var splitted=path.split("\\");
   return splitted[splitted.length-1];
}
//args
function parseArguments(args){
   if(args===""){
      var scriptPath=player.commandLine.split('"')[1];
      output.write('no arguments passed\n\r');
      output.write('usage:\n\r');
      output.write('\n\r');
      output.write(getName(scriptPath)+' "soundFile" [volume]\n\r');
      output.write('soundFile - path to sound file to play\n\r');
      output.write('volume - a number from -10000 to 0 that will set volume to the sound (0 is loudest and default value)\n\r');
      output.write('Example:\n\r');
      output.write('allplayer.bat "C:\Windows\Media\Ring05.wav" -1000\n\r');
      close();
   }
   
   //http://stackoverflow.com/a/24071183/388389
   var argarray=args.match(/"(?:\\"|\\\\|[^"])*"|\S+/g);
   if(argarray.length > 1) {
      volume=Number(argarray[1]);
   }
   
   file=argarray[0].replace (/"/g,'');   
}

function main(arguments){

   parseArguments(arguments);
   if(!existsFile(file)){
      output.write('file '+file+' does not exist\n\r');
      return;
   }   
   var fullFilename=getFullPath(file);
   var namespace=getParent(fullFilename);
   var name=getName(fullFilename);
   var objFolder=objShell.NameSpace(namespace);
   var objItem=objFolder.ParseName(name);
   var rawLen=objFolder.GetDetailsOf(objItem,lenMagicNumber);
   if(rawLen=="") {
      output.write('file '+file+' is not a media file\n\r');
      return;
   }
   
   seconds=lenToSeconds(rawLen);
   start = new Date().getTime();
   output.write('playing: '+fullFilename+' : '+rawLen+'\r\n');
   output.write('\r\n');
   //output.write(seconds+'\r\n')
   var bgsoundElems = document.getElementsByTagName('bgsound');
   bgsoundElems[0].src=fullFilename;
   bgsoundElems[0].volume=''+volume;
}

try {
    main(arguments);
}
catch(err) {
    output.write(err.message+'\r\n');
}


</script>

<script language="javascript" type="text/javascript">

window.setTimeout('close()', seconds*1000+600);

</script>
</body>
</html>
Last edited by npocmaka_ on 17 Mar 2016 02:49, edited 1 time in total.

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

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

#11 Post by Jer » 17 Mar 2016 01:25

npo...is it just me or are wav players picky about file size.
Running your batch file plays files 188KB or more, while the
smaller files are silent.

Just curious if your experience is the same.

npocmaka_
Posts: 481
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

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

#12 Post by npocmaka_ » 17 Mar 2016 02:54

Jer wrote:npo...is it just me or are wav players picky about file size.
Running your batch file plays files 188KB or more, while the
smaller files are silent.

Just curious if your experience is the same.



Which player? I've tried all and there were problems with the hta bgsound player. I've added half second additional waiting and now it plays even smaller files.Though the bgsound player have the worse performance (may be if I remove the output information it will perform better)

Here's my test:

Code: Select all

for /l %# in (1;1;10) do @htaPlayer.bat "C:\Windows\Media\Windows Navigation Start.wav" 0

for /l %# in (1;1;10) do @spPlayer.bat "C:\Windows\Media\Windows Navigation Start.wav"

for /l %# in (1;1;10) do @mediaPlayer.bat "C:\Windows\Media\Windows Navigation Start.wav"


"C:\Windows\Media\Windows Navigation Start.wav" is the smallest wav that I've found on my machine.

What file are you using? May be there's something specific in the wav files provided with the windows.

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

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

#13 Post by Jer » 20 Mar 2016 16:00

In trying the htaplayer, I find that it does not play wav files that have small byte sizes.
Windows Logon Sound.wav (157,412 bytes) is inaudible while Windows Logoff Sound.wav
(190,388 bytes) is audible.

With Audacity I recorded small wav files in 10th of a second increments. Files began sounding
at 1.1 seconds. Then a second try of those files produced sound down to .2 seconds, but not
.1 seconds. I conclude that this player works some of the time for smaller wav files.

When called from a batch file, the htaplayer closes down the calling batch file; it does not exit
the DOS window, it just does not continue in the calling batch file.

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

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

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

#14 Post by foxidrive » 21 Mar 2016 05:04

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.


Is this of any use? http://www.elifulkerson.com/projects/co ... player.php

It's for a low speced machine I seem to recall. Which OS version is it for?

Edit: another player http://skwire.dcmembers.com/wb/pages/so ... player.php

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

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

#15 Post by Jer » 21 Mar 2016 10:58

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

I did not find a wav player at the second link. There was
a file called sounder.exe that plays 2 seconds of a wav file.

My OS is Windows 7 32-bit.

Post Reply