Error 'BotFalante' object is not callable

0

I'm creating a 'virtual assistant' in Python, but with some difficulties. Here is the code:

#-*- coding: utf-8 -*-

from chatterbot.trainers import ListTrainer  
from chatterbot import ChatBot  
import pyttsx3  
import speech_recognition as sr

en = pyttsx3.init()  
en.setProperty('voice',b'brazil')  
rec = sr.Recognizer()  


class BotFalante(ChatBot):  
    def escuta(self,frase=None):  
          try:  
            with sr.Microphone() as mic:  
                fala = rec.listen(mic)  
            frase = rec.recognize_google(fala,language='pt')  
            frase = frase.replace('aprendi','aprende')  
            print(frase)  
        except sr.UnknownValueError:  
            print('Deu erro na identificação')  
            return ('')  
        return super().escuta(frase=frase)  

    def fala(self,frase):  
        en.say(frase)  
        en.runAndWait()  
        super().fala(frase)  

Bot = BotFalante('Zuleide')  
while True:  
    frase = Bot.escuta()  
    resp = Bot.pensa(frase)  
    Bot.fala(resp)  
    if resp == ('falou'):  

        break  

The error that gives is:

line 33, in <module>
resp = Bot.pensa(frase)
AttributeError: 'BotFalante' object has no attribute 'pensa'
    
asked by anonymous 30.10.2018 / 20:47

1 answer

0
resp = Bot.pensa(frase)
AttributeError: 'BotFalante' object has no attribute 'pensa'

The object Bot is an instance of class BotFalante . If you are trying to access a .pensa(...) method on this object, this pensa method must be set to one of these places: Or in the% class itself BotFalante , just as you defined the other methods escuta and fala , or inherited from one of the "parent classes" of it, such as by example of class ChatBot .

In case this method has not been defined, which is why you are getting the error.

    
30.10.2018 / 23:34