mirror of https://github.com/coqui-ai/TTS.git
Fixes a race condition with multiple simultaneous get requests. (#1807)
* Fixes a race condition with multiple simultaneous get requests. * Removed unused import * Removed unused threading import * Changed lock style to notation * make style Co-authored-by: WeberJulian <julian.weber@hotmail.fr>
This commit is contained in:
parent
bb59718c03
commit
3b7dff568a
|
@ -5,6 +5,7 @@ import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from threading import Lock
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from flask import Flask, render_template, request, send_file
|
from flask import Flask, render_template, request, send_file
|
||||||
|
@ -168,17 +169,21 @@ def details():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
lock = Lock()
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/tts", methods=["GET"])
|
@app.route("/api/tts", methods=["GET"])
|
||||||
def tts():
|
def tts():
|
||||||
text = request.args.get("text")
|
with lock:
|
||||||
speaker_idx = request.args.get("speaker_id", "")
|
text = request.args.get("text")
|
||||||
style_wav = request.args.get("style_wav", "")
|
speaker_idx = request.args.get("speaker_id", "")
|
||||||
style_wav = style_wav_uri_to_dict(style_wav)
|
style_wav = request.args.get("style_wav", "")
|
||||||
print(" > Model input: {}".format(text))
|
style_wav = style_wav_uri_to_dict(style_wav)
|
||||||
print(" > Speaker Idx: {}".format(speaker_idx))
|
print(" > Model input: {}".format(text))
|
||||||
wavs = synthesizer.tts(text, speaker_name=speaker_idx, style_wav=style_wav)
|
print(" > Speaker Idx: {}".format(speaker_idx))
|
||||||
out = io.BytesIO()
|
wavs = synthesizer.tts(text, speaker_name=speaker_idx, style_wav=style_wav)
|
||||||
synthesizer.save_wav(wavs, out)
|
out = io.BytesIO()
|
||||||
|
synthesizer.save_wav(wavs, out)
|
||||||
return send_file(out, mimetype="audio/wav")
|
return send_file(out, mimetype="audio/wav")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue