Exemplo n.º 1
0
trainer = ChatterBotCorpusTrainer(bot)

# Train the chat bot with the entire english corpus
trainer.train('chatterbot.corpus.english')

recognizer = speech_recognition.Recognizer()

while True:
    try:
        with speech_recognition.Microphone() as source:
            recognizer.adjust_for_ambient_noise(source)

            print('Say Something')
            audio = recognizer.listen(source)

            recognizer_function = getattr(recognizer, 'recognize_google')

            result = recognizer_function(audio)

            bot.get_response(text=result)
            print(bot.get_response(text=result))
    except speech_recognition.UnknownValueError:
        bot.speak('I am sorry, I could not understand that.')
    except speech_recognition.RequestError as e:
        message = 'My speech recognition service has failed. {0}'
        bot.speak(message.format(e))
    except (KeyboardInterrupt, EOFError, SystemExit):
        # Press ctrl-c or ctrl-d on the keyboard to exit
        break