forked from seongahjo/speak_like_zhang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.py
46 lines (36 loc) · 1.45 KB
/
web.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
import argparse
from flask import Flask, request, render_template, jsonify, \
send_from_directory, make_response, send_file
import os
import json
from synthesizer import Synthesizer
from utils import str2bool
AUDIO_DIR = "audio"
AUDIO_PATH = os.path.join(AUDIO_DIR)
app = Flask(__name__)
@app.route('/generate', methods=['GET'])
def generate():
text = request.args["text"]
print(text)
audio_path = synthesizer.synthesize(texts=text.split('\n'), base_path='logdir-tacotron2/generate', speaker_ids=[0],
attention_trim=True, base_alignment_path=None,
isKorean=True, config=config)[0]
return send_file(audio_path, mimetype="audio/wav",
as_attachment=True,
attachment_filename='file.wav')
@app.route('/', methods=['GET'])
def rendering():
addr = request.url_root
return render_template('index.html', addr=addr)
parser = argparse.ArgumentParser()
parser.add_argument('--sample_path', default="logdir-tacotron2/generate")
parser.add_argument('--num_speakers', default=1, type=int)
parser.add_argument('--speaker_id', default=0, type=int)
parser.add_argument('--checkpoint_step', default=None, type=int)
parser.add_argument('--base_alignment_path', default=None)
parser.add_argument('--file', type=str, default='test.wav')
parser.add_argument('--gpu', type=int, default=0)
config = parser.parse_args()
synthesizer = Synthesizer()
synthesizer.load('model', 1, None, inference_prenet_dropout=False, config=config)
app.run(host='0.0.0.0', port=80)