当我使用它时,它只会在教它另一个单词时才说话,我无法让它在目录中说出特定的答案,你们有什么意见可以解决这个问题吗?我被难住了…
@ECHO OFF @mode con cols=55 lines=10if not exist data.txt echo.>data.txt:beginset /p text="Talk: "for /f "tokens=1,* delims=@" %%i in (data.txt) do (if /i "%text%"=="%%i" ( echo Visu: %%j goto begin ) ) :Learn echo --- I don't know that. set /p answer=--- What would be a good answer to '%text%'? echo %text%@%answer%>>data.txtecho Visu: thank yougoto Aye:Ayeecho set speech = Wscript.CreateObject("SAPI.spVoice") >> "temp.vbs"echo speech.speak "%answer%" >> "temp.vbs"start temp.vbspausedel temp.vbsgoto begin
回答:
- 将Aye设置为子程序/函数,你可以用要说的文本调用它。
- 在被调用的子程序中,第一个参数是%1
@ECHO OFF mode con cols=55 lines=10if not exist data.txt Type Nul >data.txt:begincls& Echo Talk to Visuset "text=" & set /p text="Talk: "if not defined text exit /Bfor /f "tokens=1,* delims=@" %%i in (data.txt ) do if /i "%text%"=="%%i" Call :Aye "%%~j" & Goto :begin :Learnecho --- I don't know that.echo --- What would be a good answer to '%text%'set /p answer=? echo %text%@%answer%>>data.txtCall :Aye "%answer%"goto :begin:Aye echo Visu: %~1echo Visu: thank youecho set speech = Wscript.CreateObject("SAPI.spVoice") > "temp.vbs"echo speech.speak "%~1" >> "temp.vbs"cscript //Nologo temp.vbsTimeout /T 3 /Nobreak >Nuldel temp.vbsgoto :Eof