-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchatbot.py
More file actions
36 lines (32 loc) · 1.14 KB
/
chatbot.py
File metadata and controls
36 lines (32 loc) · 1.14 KB
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
30
31
32
33
34
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import os
import pyttsx3
import speech_recognition as sr
bot = ChatBot('Bot')
bot.set_trainer(ListTrainer)
engine = pyttsx3.init()
r = sr.Recognizer()
# for files in os.listdir('/Users/gaurang/Python_Practice/Corpuses/chatterbot-corpus/chatterbot_corpus/data/english/'):
# data = open('/Users/gaurang/Python_Practice/Corpuses/chatterbot-corpus/chatterbot_corpus/data/english/' + files,'r').readlines()
# bot.train(data)
initial_text = 'Hi this is Alexa!, Please give me a command'
engine.say(initial_text)
engine.runAndWait()
while True:
with sr.Microphone() as source:
print("Speak Anything.")
audio = r.listen(source)
try:
text = r.recognize_google(audio)
print("You said: {}".format(text))
if text != 'bye':
print(text)
reply = bot.get_response(text)
print('Chatbot : {}'.format(reply))
# engine.say(reply)
# engine.runAndWait()
else:
break
except:
print("sorry could not here you.")