-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
40 lines (29 loc) · 890 Bytes
/
app.py
File metadata and controls
40 lines (29 loc) · 890 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
from flask import Flask, render_template, request
import os
import gtts
import playsound
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/my-link/', methods=['GET','POST'])
def my_link():
if request.method == 'POST':
option = request.form['sentence']
cmd = 'python3 printer.py --text "%s" --quiet "-"'%(option)
os.system(cmd)
file_to_read = 'out.txt'
f = open(file_to_read, 'r')
file_text = f.read()
f.close()
audio_created = gtts.gTTS(text=file_text, lang='en')
audio_created.save('result.mp3')
file = open("out.txt")
line = file.read().replace("\n"," ")
file.close()
return render_template("index.html",out = line)
@app.route('/speak/', methods =['GET','POST'])
def speak():
playsound.playsound('result.mp3')
if __name__ == '__main__':
app.run(debug=True)