最后发布: 2020-08-03
我将提供一部分代码。在while块内使用命令后,它不会继续。我认为是代码块text = get_audio().lower()给我带来了错误。
def process_text():
pass
if __name__ == "__main__":
assistant_speaks('''Hello, I am a Virtual Assistant.
I am here to make your life easier. You can command me to perform
various tasks such as calculating sums or opening applications.
Please tell me who you are.''')
name = 'are'
name = get_audio()
assistant_speaks("Hello, " + name + '.')
while 1:
assistant_speaks("What can i do for you?" + name + '.')
text = get_audio().lower()
if text == 0:
continue
if "exit" in str(text) or "bye" in str(text) or "sleep" in str(text):
assistant_speaks("Ok bye, " + name + '.')
break
# calling process text to process the query
process_text()
def process_text():
try:
if 'search' in input or 'play' in input:
# a basic web crawler using selenium
search_web(input)
return
elif "who are you" in input or "define yourself" in input:
speak = '''Hello, I am a virtual assistant.
I am here to make your life easier. You can command me to perform
various tasks such as calculating sums or opening applications.'''
assistant_speaks(speak)
return
基本上,当我问elifs的时候,它没有回答任何问题。过了try。
有人有什么想法吗?
function while-loop artificial-intelligence为了从你的程序中得到你想要的行为,你至少应该纠正三个错误。
input
与 text
里面 try
块。在Python中。input
是一个内置函数,而不是一个字符串。你已经将用户的答案分配给了变量 text
所以为什么不用那个呢?)process_text
功能 之前 你叫它。实际上,你应该把你调用的那条线移动到 process_text()
在该函数定义后的某个地方。process_text()
函数:你应该把这行取消缩进一级,否则它将被执行在 if "exit" in ...
块。您还应该定义 process_text
前,因为你只需要定义一次。
4我的应用程序无法在三星Note 8的Google Play商店上显示
5maven-assembly-plugin无法按预期打包依赖项
9Matlab-如何从两个或多个向量创建矩阵,该矩阵表示每个向量中单个元素的每种组合[重复]
10mutableArrayValueForKey和直接调用insertObject:inEmployeesAtIndex:之间的区别
11request.getSession()。getServletContext()。getRealPath()的替代方法
14在Apache nifi中合并消息后,无法从SQS删除消息
17带有背景图像的JFrame和使用setLocation的JButton对我不起作用?