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>