我正在制作一个聊天机器人,我正在尝试创建一个获取问题并以某种方式响应的函数,但我收到一个错误,指出TypeError: argument of type 'function' is not iterable
“def quanda”部分中的 if 语句我该如何解决这个问题?
import os
import speech_recognition as sr
from gtts import gTTS
import playsound
import time
def speak(text):
tts = gTTS(text=text, lang="en")
filename = "voice.mp3"
tts.save(filename)
playsound.playsound(filename)
def get_audio():
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
said = ""
try:
said = r.recognize_google(audio)
print(said)
except Exception as e:
print("Exception: " + str(e))
return said
def qanda(question, response):
text = get_audio
if question in text:
speak(response)
return response
speak("hello, how can i help you?")
text = get_audio
qanda("hello", "hi there")
quanda("what is the weather", "Its 27 degrees")