0

I am making a chatbot and I am trying to create a function that gets a question and responds in a certain way but I receive an error that says TypeError: argument of type 'function' is not iterable regarding the if statement in the "def quanda" section how can I solve this issue?

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")
ngShravil.py
  • 4,742
  • 3
  • 18
  • 30
Anthony
  • 1
  • 1
  • You are already passing strings to the function, if you must convert objects to strings you should use `str` - `str(question)` – Iain Shelvington Sep 08 '19 at 01:50
  • Possible duplicate of [Converting integer to string?](https://stackoverflow.com/questions/961632/converting-integer-to-string) – cronoik Sep 08 '19 at 01:51

1 Answers1

2

Thats because get_audio is a method, you need to call it with (). So, whereever you care calling get_audio method call it like this: get_audio().

ngShravil.py
  • 4,742
  • 3
  • 18
  • 30