from flask import Flask, request, send_file from flask.views import MethodView from hparams import hparams, hparams_debug_string import argparse import os from synthesizer import Synthesizer from flask_cors import CORS import io app = Flask(__name__) CORS(app) html_body = '''Demo

''' synthesizer = Synthesizer() class Mimic2(MethodView): def get(self): text = request.args.get('text') if text: wav, _ = synthesizer.synthesize(text) audio = io.BytesIO(wav) return send_file(audio, mimetype="audio/wav") class UI(MethodView): def get(self): return html_body ui_view = UI.as_view('ui_view') app.add_url_rule('/', view_func=ui_view, methods=['GET']) mimic2_api = Mimic2.as_view('mimic2_api') app.add_url_rule('/synthesize', view_func=mimic2_api, methods=['GET']) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--checkpoint', required=True, help='Full path to model checkpoint') parser.add_argument('--port', type=int, default=3000) parser.add_argument('--hparams', default='', help='Hyperparameter overrides as a comma-separated list of name=value pairs') parser.add_argument( '--gpu_assignment', default='0', help='Set the gpu the model should run on') args = parser.parse_args() os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu_assignment os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' hparams.parse(args.hparams) print(hparams_debug_string()) synthesizer.load(args.checkpoint) app.run(host='0.0.0.0', port=args.port)