user Enable\disable 部分代码批量

user Enable\disable parts of the code in batch

在我的批次中,我使用文字转语音。但是有没有一种方法可以设置一种语法,使用户可以选择在批处理中启用或禁用文本到语音转换,而不必在整个代码中编写 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

你的问题不清楚。你想根据用户的选择执行一些行吗?你可以用一个小技巧来做到这一点:

@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,您当然也可以将其应用到您的菜单中。