-
Notifications
You must be signed in to change notification settings - Fork 0
/
james.py
29 lines (24 loc) · 892 Bytes
/
james.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from chatterbotapi import ChatterBotFactory, ChatterBotType
import speech_recognition as sr
import sys
import subprocess
r = sr.Recognizer()
r.energy_threshold = 4000
r.dynamic_energy_threshold = True
factory = ChatterBotFactory()
bot1 = factory.create(ChatterBotType.CLEVERBOT)
bot1session = bot1.create_session()
user_input = "Say something to begin..."
print(user_input)
while True:
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
audio = r.listen(source, timeout = None)
try:
user_input = r.recognize(audio)
print("User: " + user_input)
except LookupError:
print("Could not understand you")
s = bot1session.think(user_input);
subprocess.call('espeak -k20 -s135 -ven-rp+m7 "{0}" 2>/dev/null' .format(s), shell=True)
print 'James: ' + s