【发布时间】:2016-04-14 20:19:00
【问题描述】:
刚开始学习编程并开始涉足简单的聊天机器人代码。我收到了文本回复,但是我希望我的计算机 (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])
如果这是重复,我很抱歉。我更需要在这个结构中安装解决方案,尽管只是为了帮助我了解它的放置位置以及如何使用它。
注意: 这不是对标记问题的欺骗。尽管这被认为是重复的问题确实允许您将文本转换为语音,但它不涉及将列出的随机响应转换为语音,这是我需要做的。然而,它确实让我能够让演讲发挥作用,所以谢谢你。我在别处找到了答案并将其放在下面。
【问题讨论】:
-
要格式化代码,选择块并按下工具栏中看起来像花括号的按钮。它完美地工作。您不需要在每一行代码之间添加额外的空白行。
-
I'm more in need of fitting the solution within this structure是说“为我做”的一种奇特方式。听起来您找到了您需要的东西,但不想花时间去学习它以使用它。 -
@takendarkk 不,这很可能会被设置为一个被骗的问题。问题是,已经有答案的问题可能用于不同的结构,我不理解的结构。我需要知道如何将特定代码放在这个特定的结构中以便我理解它。
-
那么,您是否尝试将其他代码放入您的结构中?如果你这样做了,你就没有向我们展示。如果你没有,那应该是第 1 步。
标签: artificial-intelligence text-to-speech chatbot