I'm trying to make a random choice generator, so you can ask an AI say, "one or two", and it'll give you a randomly generated answer. I get this error: "Traceback (most recent call last): File "C:/Users/Jeff/PycharmProjects/pythonProject/main.py", line 246, in answer = next(res.results).text StopIteration"
It's easy to make something choose a random choice with the options being one characters like "one or two", but I want it to be able to choose between sentences like "going to the beach or staying home", here's my code:
words = output.split()
if words[1] == 'or':
choices = [words[0] + output.replace(words[2], '') + output.replace('or', ''), words[2] + output.replace(words[0], '') + output.replace('or', '')]
choice = random.choice(choices)
language = 'en'
voice = gTTS(text=choice, lang=language, slow=False)
voice.save("voice.mp3")
os.system("start voice.mp3")
print(choice)
Aucun commentaire:
Enregistrer un commentaire