在我的批处理中,我使用文字转语音。但有没有办法设置一种语法,让用户可以选择在批处理中启用或禁用文本到语音,而无需在整个代码中写入相同的语法100次?
编辑:
random program
ok so heres the problem. below theres just something i threw together that got no function exept for explaining what i intend to do.
what i wonder is that: when the user starts the main program. (with main menu) he/she will get the option to toggle on/off the "text to speech for the entire program.
etc
if user of the program chooses to disable the text to speech function. and then decides to run program1. (as u can see theres a text to speech part in program1)
but since he previously in main menu selected DISABLE for voice. then it will not play the voice in program 1,2 or 3. even the script is there. it gets sort of "turned off" until user chooses to turn this function back on. (without manual edit of each line)
is this possiblie? im quite sorry if u didnt understand my explaination. im not very good at explaining. but i hope you understood it :P
========================================================================================================================================
:main
title random program
(heres the menu of the program)
:program 1:
REM (random program script here)
set text="this is the part i wish to be able for users to toggle on/off"
goto num
:num
set num=%random%
if exist temp%num%.vbs goto num
echo ' > "temp%num%.vbs"
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "temp%num%.vbs"
echo speech.speak "%text%" >> "temp%num%.vbs"
start temp%num%.vbs
pause>nul
del temp%num%.vbs
goto program2
:program2
REM (random program script here)
set text="this is the part i wish to be able for users to toggle on/off"
goto num
:num
set num=%random%
if exist temp%num%.vbs goto num
echo ' > "temp%num%.vbs"
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "temp%num%.vbs"
echo speech.speak "%text%" >> "temp%num%.vbs"
start temp%num%.vbs
pause>nul
del temp%num%.vbs
goto program4
:program3
REM (random program script here)
set text="this is the part i wish to be able for users to toggle on/off"
goto num
:num
set num=%random%
if exist temp%num%.vbs goto num
echo ' > "temp%num%.vbs"
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "temp%num%.vbs"
echo speech.speak "%text%" >> "temp%num%.vbs"
start temp%num%.vbs
pause>nul
del temp%num%.vbs
goto main
答案 0 :(得分:2)
你的问题不清楚。您想根据用户选择执行一些行吗?你可以用一个小技巧来做到这一点:
@echo off
choice /c YN /M "Enable?"
if errorlevel 2 (set "do=REM") else (set "do=")
echo Hello
%do% echo maybe...
修改强> 在我的脚本中实现我的答案(我可以自由地改变它 - 不需要一遍又一遍地编写相同的代码)
@echo off
:main
choice /c YN /M "Enable speech?"
if errorlevel 2 (set "do=REM") else (set "do=")
title random program
echo (heres the menu of the program)
:program 1:
echo REM (random program script 1 here)
set text="you just executed random script one"
%do% call :speak
goto program2
:program2
echo REM (random program script 2 here)
set text="This was the second random script"
%do% call :speak
goto program3
:program3
echo REM (random program script 3 here)
set text="And this is the third of them."
%do% call :speak
rem goto main
goto :eof
:Speak
set num=%random%
if exist speak%num%.vbs goto :speak
echo set speech = Wscript.CreateObject("SAPI.spVoice") > "speak%num%.vbs"
echo speech.speak %text% >> "speak%num%.vbs"
speak%num%.vbs
del speak%num%.vbs
您可以使用choice
代替使用class Bus {
String number;
Bus(int n) {
number = String.valueOf(n);
}
}
,当然也可以将其实现到您的菜单中。