Estou criando um 'assistente virtual' em Python, mas to com algumas dificuldades. Segue o código:
#-*- 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
O erro que da é:
line 33, in <module>
resp = Bot.pensa(frase)
AttributeError: 'BotFalante' object has no attribute 'pensa'
resp = Bot(frase)
? No que você postou não tem.ChatBot
define o método__call__
para ser chamável desta forma?BotFalante
deveria possuir o métodopensa
? Você não definiu ele.