刚开始学习编程并开始涉足简单的聊天机器人代码。我收到了文本回复,但是我希望我的计算机 (Mac) 能够说出回复,并且只在回复出现的同时说出回复。这是代码:
import random
import sys
import os
def show_response(options):
choice = random.randint(0, len(options) -1)
print(options[choice])
random.seed(None)
while True:
userInput = input(">>>")
if userInput in ["Ava, you there?"]:
list = ["Indeed I am, Sir.", "Yes, Sir. What do you need?", "For you, Sir, always.", "I am now.", "What is it, Sir?", "I'm right here.", "How may I assist you, Sir?", "How may I assist you?", "You need something, Sir?"]
choice = random.randint(0, len(list) -1)
print(list[choice])
elif userInput in ["Wake up, Ava"]:
list = ["What is it, Sir?", "How can I help?", "How can I help, Sir?", "Hello, Sir.", "Hello, Sir. Is there anything you need?", "How may I assist you?", "How may I assist you, Sir?"]
choice = random.randint(0, len(list) -1)
print(list[choice])
elif userInput in ["Hey, Ava"]:
list = ["What is it, Sir?", "How can I help?", "How can I help, Sir?", "Hello, Sir.", "Hello, Sir. Need anything?", "How may I assist you?", "How may I assist you, Sir?", "You need something, Sir?"]
choice = random.randint(0, len(list) -1)
print(list[choice])
如果这是重复,我很抱歉。我更需要在这个结构中安装解决方案,尽管只是为了帮助我了解它的放置位置以及如何使用它。
注意:这不是标记问题的欺骗。虽然这个被认为是重复的问题确实允许您将文本转换为语音,但它不涉及将列出的随机响应转换为语音,这是我需要做的。然而,它确实让我能够让演讲发挥作用,所以谢谢你。我在别处找到了答案并将其放在下面。