Update xtts.py
Browse files
xtts.py
CHANGED
@@ -8,13 +8,15 @@ import scipy
|
|
8 |
from TTS.api import TTS
|
9 |
|
10 |
import torch
|
11 |
-
import torchaudio
|
12 |
|
13 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
|
|
14 |
# def upload_bytes(bytes, ext=".wav"):
|
15 |
# return bytes
|
|
|
|
|
16 |
|
17 |
-
from qili import upload, upload_bytes
|
18 |
# if __name__ == "__main__":
|
19 |
# app = Flask(__name__)
|
20 |
# else:
|
@@ -38,12 +40,16 @@ def predict(text, sample=None, language="zh"):
|
|
38 |
global model
|
39 |
try:
|
40 |
text= re.sub("([^\x00-\x7F]|\w)(\.|\。|\?)",r"\1 \2\2",text)
|
41 |
-
|
|
|
42 |
text,
|
43 |
language=language if language is not None else "zh",
|
44 |
speaker_wav=sample if sample is not None else default_sample[0],
|
|
|
45 |
)
|
46 |
|
|
|
|
|
47 |
with io.BytesIO() as wav_buffer:
|
48 |
if torch.is_tensor(wav):
|
49 |
wav = wav.cpu().numpy()
|
@@ -152,29 +158,6 @@ def tts_play():
|
|
152 |
url=convert()
|
153 |
return playInHTML(url)
|
154 |
|
155 |
-
@app.route("/clone")
|
156 |
-
def clone():
|
157 |
-
global tts
|
158 |
-
get_tts()
|
159 |
-
source=request.args.get('source')
|
160 |
-
sample=request.args.get('sample')
|
161 |
-
if not source:
|
162 |
-
return "No source", 400
|
163 |
-
|
164 |
-
source=download(source)
|
165 |
-
output=tempfile.mktemp(suffix=".wav")[1]
|
166 |
-
tts.voice_conversion_to_file(
|
167 |
-
source_wav=source,
|
168 |
-
target_wav=sample,
|
169 |
-
file_path=output
|
170 |
-
)
|
171 |
-
return upload(output)
|
172 |
-
|
173 |
-
@app.route("/clone/play")
|
174 |
-
def clone_play():
|
175 |
-
url=clone()
|
176 |
-
return playInHTML(url)
|
177 |
-
|
178 |
|
179 |
@app.route("/setup")
|
180 |
def get_tts():
|
@@ -188,10 +171,10 @@ def get_tts():
|
|
188 |
model_name="tts_models/multilingual/multi-dataset/xtts_v2"
|
189 |
logging.info(f"loading model {model_name} ...")
|
190 |
tts = TTS(
|
191 |
-
|
192 |
-
model_path=model_path,
|
193 |
-
config_path=config_path,
|
194 |
-
vocoder_config_path=vocoder_config_path,
|
195 |
progress_bar=True
|
196 |
)
|
197 |
model=tts.synthesizer.tts_model
|
@@ -208,4 +191,4 @@ def get_tts():
|
|
208 |
@app.route("/")
|
209 |
def hello():
|
210 |
return "welcome!"
|
211 |
-
logging.info("xtts is ready")
|
|
|
8 |
from TTS.api import TTS
|
9 |
|
10 |
import torch
|
|
|
11 |
|
12 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
13 |
+
|
14 |
+
from qili import upload, upload_bytes
|
15 |
# def upload_bytes(bytes, ext=".wav"):
|
16 |
# return bytes
|
17 |
+
# def upload(file):
|
18 |
+
# return file
|
19 |
|
|
|
20 |
# if __name__ == "__main__":
|
21 |
# app = Flask(__name__)
|
22 |
# else:
|
|
|
40 |
global model
|
41 |
try:
|
42 |
text= re.sub("([^\x00-\x7F]|\w)(\.|\。|\?)",r"\1 \2\2",text)
|
43 |
+
output=tempfile.mktemp(suffix=".wav")
|
44 |
+
wav = tts.tts_to_file(
|
45 |
text,
|
46 |
language=language if language is not None else "zh",
|
47 |
speaker_wav=sample if sample is not None else default_sample[0],
|
48 |
+
file_path=output
|
49 |
)
|
50 |
|
51 |
+
return upload(output)
|
52 |
+
|
53 |
with io.BytesIO() as wav_buffer:
|
54 |
if torch.is_tensor(wav):
|
55 |
wav = wav.cpu().numpy()
|
|
|
158 |
url=convert()
|
159 |
return playInHTML(url)
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
@app.route("/setup")
|
163 |
def get_tts():
|
|
|
171 |
model_name="tts_models/multilingual/multi-dataset/xtts_v2"
|
172 |
logging.info(f"loading model {model_name} ...")
|
173 |
tts = TTS(
|
174 |
+
model_name,
|
175 |
+
# model_path=model_path,
|
176 |
+
# config_path=config_path,
|
177 |
+
# vocoder_config_path=vocoder_config_path,
|
178 |
progress_bar=True
|
179 |
)
|
180 |
model=tts.synthesizer.tts_model
|
|
|
191 |
@app.route("/")
|
192 |
def hello():
|
193 |
return "welcome!"
|
194 |
+
logging.info("xtts is ready")
|