File size: 953 Bytes
bcfd9f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, redirect, url_for, request
import gradio as gr
from synthesize import synthesize, load_model
from synthesis.vocoders import Hifigan
import sounddevice as sd
import soundfile as sf

model = load_model("checkpoints/checkpoint_9000.zip")
vocoder = Hifigan("weights/custom_pctest/model.pt", "weights/custom_pctest/config.json")

def inference(text: str):
    synthesize(
        model=model,
        text=text,
        graph_path="graph.png",
        audio_path="audio.wav",
        vocoder=vocoder,
    )
    return "audio.wav"

app = Flask(__name__)

@app.route('/process',methods = ['POST'])
def login():
   if request.method == 'POST':
        text = request.json['text']
        inference(text)
        data, fs = sf.read("audio.wav", dtype='float32')  
        sd.play(data, fs)
        status = sd.wait()  # Wait until file is done playing
        return {'success': True}

if __name__ == '__main__':
   app.run(debug = True)