-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflask_aac_irish.py
97 lines (91 loc) · 3.3 KB
/
flask_aac_irish.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from flask import Flask, render_template
import os
import glob
app = Flask(__name__)
basedir = os.path.abspath(os.path.dirname(__file__))
voice_type = "irish_1"
alpha = 0.4
all_pass_filter = 0
@app.route('/', methods=['POST', 'GET'])
def home_page():
from flask import request
if request.method == 'POST':
text = request.form['text']
voice_type = request.form['voice']
from tts_corrector import tts_corrector
_, sound_file = tts_corrector(text, voice_type)
file = sound_file.json()
sound = file["audioContent"]
import base64
sound_ = base64.b64decode(sound)
import io
mem = io.BytesIO()
mem.write(sound_)
mem.seek(0)
from flask import send_file
return send_file(mem, mimetype="audio/mp3")
return '''
<form method="post">
<p><input type=text name=text>
<label for="voice">Choose a voice:</label>
<select id="voice" name="voice">
<option value="Ulster">Ulster</option>
<option value="Connaught">Connaught</option>
<option value="Connaught (girl)">Connaught (girl)</option>
<option value="Connaught (boy)">Connaught (boy)</option>
<option value="Munster">Munster</option>
</select>
<p><input type=submit value=Submit>
</form>
'''
@app.route('/corrector', methods=['POST', 'GET'])
def corrector():
from flask import request
if request.method == 'POST':
text = request.form['text']
from an_gramadoir import correct_errors_in_text
corrected_text = correct_errors_in_text(text)
return {
"text": corrected_text,
}
return '''
<form method="post">
<p><input type=text name=text>
</form>
'''
@app.route('/voice', methods=['POST', 'GET'])
def voice():
from flask import request
if request.method == 'POST':
files = glob.glob(f'{os.path.join(basedir,"static/sounds/*.mp3")}')
# deleting the files with txt extension
for file in files:
os.remove(file)
text = request.form['text']
voice_type = request.form['voice']
alpha = request.form['alpha']
all_pass_filter = request.form['filter']
if text == "":
return render_template("index.html",alpha=alpha,all_pass_filter=all_pass_filter)
from tts_corrector import tts_corrector_with_hts_params
_, sound_file = tts_corrector_with_hts_params(text, voice_type,alpha,all_pass_filter)
file = sound_file.json()
sound = file["audioContent"]
import base64
sound_ = base64.b64decode(sound)
import io
mem = io.BytesIO()
mem.write(sound_)
mem.seek(0)
from datetime import datetime
now = datetime.now()
date_time = now.strftime("%m%d%Y%H%M%S")
filename = f"sound_{date_time}.mp3"
filename_to_save = os.path.join(basedir,"static/sounds", filename)
with open(filename_to_save, "wb") as file_to_save:
file_to_save.write(sound_)
return render_template("index.html",filename=f"/sounds/{filename}",alpha=alpha,all_pass_filter=all_pass_filter)
return render_template("index.html")
if __name__ == "__main__":
app.debug = True
app.run()