This question is based on my previous question here .
Major of these below codes are combination from @Hackoo answer(many thanks to Him) and some other users from SO. And I made a very little effort to combine them with other's codes to arrange a simple tutorial board which can :
- paste user input(hidden) using number 1 and automatically entered without pressing enter.
- typewriting the input with type writer.
- read and speak the input.
For now, it is working as intended. The full codes is as follow :
@echo off
title %~nx0
color 0a
setlocal EnableDelayedExpansion
set color_white=%ESC%[37m
set color_black=%ESC%[30m
:menuLOOP
Color 0A & Mode con cols=78 lines=25
echo(
echo( ===============================================================
::set choice=
choice /c 12345 /n /m " "
IF errorlevel 5 goto choice5
IF errorlevel 4 goto choice4
IF errorlevel 3 goto choice3
IF errorlevel 2 goto choice2
IF errorlevel 1 goto choice1
:choice1 INPUT TYpewriter
call :menu_[1]
GOTO:menuLOOP
:choice2 PLAY TYpewriter Audio
call :menu_[2]
GOTO:menuLOOP
:choice3 STOP TYpewriter Audio
call :menu_[3]
GOTO:menuLOOP
:choice4 PLAYLoop TYpewriter Audio
call :menu_[4]
GOTO:menuLOOP
:choice5
call :menu_[5]
GOTO:menuLOOP
::********************************************************************************************
:menu_[1] input
cls
echo:
set SendKeys=CScript //nologo //E:JScript "%~F0"
echo pasteclip= CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text") > temp.vbs
echo WScript.Echo pasteclip >> temp.vbs
cscript //nologo temp.vbs > temp.txt
set color_white=%ESC%[37m
set color_black=%ESC%[30m
REM for /f "Tokens=* Delims=" %%x in (temp.txt) do set SendPaste=%%x
REM set "text=%SendPaste%"%color_black%
set "File2Read=temp.txt"
rem This will read a file into an array of variables and populate it
setlocal EnableExtensions EnableDelayedExpansion
for /f "delims=" %%a in ('Type "%File2Read%"') do (
set /a count =1
set "Line[!count!]=%%a"
)
rem Display array elements
@For /L %%i in (1,1,%Count%) do (
:: You should call this Call :Typewriter "!Line[%%i]!" inside the loop for /L
Call :Typewriter "!Line[%%i]!"
)
GOTO:menuLOOP
::********************************************************************************************
:menu_[2] Play TYpewriter Audio
cls & color 0A
Call:SkipLine 10
Call:Tab 3
::echo %x% Please Wait for a while .. Launching DJ Buzz Radio ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\DJBuzzRadio.vbs
Set URL=Typewriter-sound.mp3
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[3] Stop the music
cls & color 0C
Call:SkipLine 10
Call:Tab 3
::echo %x% Please Wait for a while .. Stopping the music ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[4] PlayLoop TYpewriter Audio
cls & color 0A
Call:SkipLine 10
Call:Tab 3
::echo %x% Please Wait for a while .. Launching DJ Buzz Radio ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\DJBuzzRadio.vbs
Set URL=Typewriter-sound.mp3
Call:PlayLoop %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
::********************************************************************************************
:Play
(
echo Play "%~1"
echo Sub Play(URL^)
echo Dim Sound
echo Set Sound = CreateObject("WMPlayer.OCX"^)
echo Sound.URL = URL
echo Sound.settings.volume = 100
echo Sound.Controls.play
echo do while Sound.currentmedia.duration = 0
echo wscript.sleep 100
echo loop
echo wscript.sleep (int(Sound.currentmedia.duration^) 1^)*1000
echo End Sub
)>%~2
::*********************************************************************************************
::********************************************************************************************
:PlayLoop
(
echo Play "%~1"
echo Sub Play(URL^)
echo Dim Sound
echo Set Sound = CreateObject("WMPlayer.OCX"^)
echo Sound.URL = URL
echo Sound.settings.volume = 100
echo Sound.settings.setMode "loop", True
echo Sound.Controls.play
echo While Sound.playState ^<^> 1
echo WScript.Sleep 100
echo Wend
echo End Sub
)>%~2
::*********************************************************************************************
::*********************************************************************************************
:Tab
set "x="
For /L %%I In (1,1,%1) Do Set "x=!x! "
REM ^-- this is a TAB
goto :eof
::*********************************************************************************************
:SkipLine
For /L %%I In (1,1,%1) Do Echo(
Goto:Eof
:EOF
EXIT
::*********************************************************************************************
::*********************************************************************
:TypeWriter
Cls
echo(
(
echo strText=wscript.arguments(0^)
echo intTextLen = Len(strText^)
echo intPause = 150
echo For x = 1 to intTextLen
echo strTempText = Mid(strText,x,1^)
echo WScript.StdOut.Write strTempText
echo WScript.Sleep intPause
echo Next
echo Set Voice=CreateObject("SAPI.SpVoice"^)
echo voice.speak strText
)>%tmp%\%~n0.vbs
@cScript.EXE /noLogo "%tmp%\%~n0.vbs" ^" ^
%empty line%
^
%empty line%
%~1^"
exit /b
::*********************************************************************
:: Most helpful references to arrange this batch:
::https://stackoverflow.com/questions/28369536/batch-file-typewriter-effect
::https://stackoverflow.com/questions/664957/can-i-mask-an-input-text-in-a-bat-file?lq=1
::https://stackoverflow.com/a/63847096/9222942 mask with black
::https://stackoverflow.com/a/24792070/9222942 can-i-mask-an-input-text-in-a-bat-file
::https://stackoverflow.com/a/62121081/9222942 how-can-you-get-the-clipboard-contents-with-a-windows-command
::https://stackoverflow.com/a/31880899/9222942 how-to-play-invisible-music-in-a-batch-file
::https://stackoverflow.com/a/21205537/9222942 automatically-accept-user-input-windows-batch
::https://stackoverflow.com/a/16116676/9222942 how-to-read-file-contents-into-a-variable-in-a-batch-file
But a problem is that, this batch store every clipboard beginning from running the first command 1.
Let say, for the first time i copied sentence 1 with text "Summarize the problem". After running the batch, by pressing 1 , the input sentence 1 should then be typewritten to cmd.
Then when i copied sentence 2 with text let say "describe what you've tried" , it will repeat the sentence 1 , and only after finishing the sentence 1 it will write sentence 2.
Even when I do copy for the third time, the forth, it will also repeat from the very first clipboard(i.e sentece 1, sentence 2 and so on)
My question is, how to stop the repeatation of the first clipboard sentence?
I've tried manually delete the temp.txt and the temp.vbs after running the first command but didnt help.
Also i've tried using cmd /c “echo off | clip” which is from here . I've applied it as follow :
@For /L %%i in (1,1,%Count%) do (
:: You should call this Call :Typewriter "!Line[%%i]!" inside the loop for /L
Call :Typewriter "!Line[%%i]!"
cmd.exe /c echo.|clip
)
, but also didnt work.
Could someone please help on how to clear the the repeatation?
CodePudding user response:
As instructed by Sir Stephan(all credit goes to Him), all i need to do is add set "Count=0" before the 1st for loop that counts the lines :
setlocal EnableExtensions EnableDelayedExpansion
set "Count=0"
for /f "delims=" %%a in ('Type "%File2Read%"') do (
set /a count =1
set "Line[!count!]=%%a"
)
rem Display array elements
@For /L %%i in (1,1,%Count%) do (
:: You should call this Call :Typewriter "!Line[%%i]!" inside the loop for /L
Call :Typewriter "!Line[%%i]!"