-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (32 loc) · 778 Bytes
/
main.py
File metadata and controls
45 lines (32 loc) · 778 Bytes
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
35
36
37
38
39
40
41
42
43
44
45
from chatterbot.trainers import ListTrainer
from chatterbot import ChatBot
import os
import speech_recognition as sr
import sys
import pyttsx3
#gets audio
r = sr.Recognizer()
with sr.Microphone() as source:
print("Speak:")
audio = r.listen(source)
#converts speech to text
speech = r.recognize_google(audio)
print(speech)
bot = ChatBot('Test')
bot.set_trainer(ListTrainer)
for _file in os.listdir('database'):
chats=open('database/'+_file,'r').readlines()
bot.train(chats)
request = speech
f=open("db.txt","a+")
f.write(request+'\n')
f.close()
f=open("db.txt","r")
contents=f.readlines()
f.close()
response = bot.get_response(request)
print(response)
#convert text back to speech
engine = pyttsx3.init()
engine.say(response)
engine.runAndWait()