函数PoNanswer应返回True或False,它是一个循环,只有当您说是时才能停止,...或者不,..。当你说出来的时候,它应该会回来。但非常奇怪的是,它没有返回...如何修复它?提前感谢您)
def PoNanswer(voice_data):
for i in pANSWER_LIST:
if i in voice_data.split():
print('true')
return True
for i in nANSWER_LIST:
if i in voice_data.split():
print('false')
return False
voice_data = record_audio('I did not get it. Please repeat')
PoNanswer(voice_data)
class Command:
def __init__(self, raw_command):
self.raw_command = raw_command
self.key_word = False
self.action_word = False
self.processing()
def processing(self):
print(self.raw_command)
for i in self.raw_command.split():
if i in COMMANDS_LIST:
self.key_word = i
elif i in ACTION_WORD_LIST:
self.action_word = i
if self.key_word == COMMANDS_LIST[0]:
if self.action_word:
speak('ordering...')
main('-//-')
else:
if PoNanswer(record_audio(ADDITIONAL_QUESTIONS[0])):
self.raw_command = self.raw_command + "order"
print("mod")
self.processing()
else:
speak('Okay')
main('-//-')
self.processing()发布于 2020-10-24 01:33:15
在本例中,我应该使用循环( while 1: ),而不是在函数内部调用相同的函数。
def PoNanswer(voice_data):
while 1:
for i in pANSWER_LIST:
if i in voice_data.split():
return True
for i in nANSWER_LIST:
if i in voice_data.split():
return False
voice_data = record_audio('I did not get it. Please repeat')幸运的是,这个^正在工作。
def func(var):
...
func(var)这^不是,我不知道为什么,但我很高兴它现在工作了))
https://stackoverflow.com/questions/64504315
复制相似问题