-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
48 lines (34 loc) · 959 Bytes
/
app.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
from flask import Flask, render_template, request
from flask import jsonify
from chatterbot import ChatBot
import speech_recognition as sr
import sys
import pyttsx3
from chatterbot.trainers import ListTrainer
app = Flask(__name__)
bot = ChatBot('New')
bot.set_trainer(ListTrainer)
for _file in os.listdir('database'):
chats=open('database/'+_file,'r').readlines()
bot.train(chats)
@app.route("/")
def home():
return render_template("index.html")
@app.route("/get")
def get_bot_response():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Speak:")
audio = r.listen(source)
speech = r.recognize_google(audio)
userText = speech
engine = pyttsx3.init()
engine.say(str(bot.get_response(userText)))
engine.runAndWait()
return jsonify(
bot = str(bot.get_response(userText)),
user = str(userText),
)
if __name__ == "__main__":
app.run()