我试图让一个python文本到语音程序无限运行,直到用户决定退出,任何帮助将不胜感激这是我的代码:# IMPORTimport gtts as gTTSimport os # TTSmyText = input("Enter your text: ")language = 'en'output = gTTS.gTTS(text=myText,, slow=False,)output.save("output.mp3")os.system("start output.mp3")# Restartdef get_answer(prompt): answer = input(prompt) # 1 while not (answer == "yes" or answer == "no" # 2 while answer not in ("yes", "no"): # 3 while answer not in ["yes", "no"]: while answer not in ("yes", "no"): answer = input(prompt) return answerprint(get_answer("yes or no? "))
1 回答
繁花不似锦
TA贡献1851条经验 获得超4个赞
# IMPORT
import gtts as gTTS
import os
# FUNCTIONS
def get_answer(prompt):
answer = input(prompt)
# 1 while not (answer == "yes" or answer == "no"
# 2 while answer not in ("yes", "no"):
# 3 while answer not in ["yes", "no"]:
while answer not in ("yes", "no"):
answer = input(prompt)
return answer
# TTS
while True:
myText = input("Enter your text: ")
language = 'en'
output = gTTS.gTTS(text=myText,, slow=False,)
output.save("output.mp3")
os.system("start output.mp3")
# Restart
if get_answer("quit (yes or no?): ") == yes: break #break out of the loop
添加回答
举报
0/150
提交
取消