Raspberry Pi – Cleverbot Voice Communication

Using my first generation Raspberry Pi and a few USB / analog devices, i’ve been able to create (a rather slow) cleverbot voice communicator.

The reason for the slow down is initialization and listening on the USB microphone, but other than that everything works as expected.

#!/usr/bin/env python

import speech_recognition as sr
import pyttsx
import cleverbot

print 'Initializing, please wait...'

# define our cleverbot
cb = cleverbot.Cleverbot()

# speech recognizer setup
r = sr.Recognizer()

# engine for text to speech
engine = pyttsx.init()
#engine.setProperty('rate', 20)

while True:

    # obtain audio from the microphone
    # this is the bit of code that take a long time...
    with sr.Microphone() as source:
	print("Talk to cleverbot!")
	audio = r.listen(source)

    phrase = r.recognize_google(audio)
    print '  me: %s' % phrase
    resp = cb.ask(phrase)
    print '  cleverbot: %s' % resp