'Botfalante' error Object is not callable

Asked

Viewed 343 times

0

I am creating a virtual wizard in Python, but with some difficulties. Follow 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 mistake that is:

line 33, in <module>
resp = Bot.pensa(frase)
AttributeError: 'BotFalante' object has no attribute 'pensa'
  • 1

    And at what point in the code there is resp = Bot(frase)? What you posted is missing.

  • No while, the correct is: phrase = Bot.escuta() Resp = Bot(phrase) Bot.fala(Resp) if Resp == ('said'):

  • The class ChatBot defines the method __call__ to be called this way?

  • i commited a misconception, I just corrected the code, sorry

  • So the question becomes class BotFalante should have the method pensa? You didn’t define him.

1 answer

0


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

The object Bot is an instance of the class BotFalante. If you are trying to access a method .pensa(...) in that respect, that method pensa needs to be defined in one of these places: Or in the class itself BotFalante, the same way you defined the other methods escuta and fala, or inherited from one of her "parent classes", as per my class ChatBot.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.