Update xtts.py
Browse files
xtts.py
CHANGED
@@ -34,30 +34,29 @@ if not os.path.exists(sample_root):
|
|
34 |
default_sample=f'{os.path.dirname(os.path.abspath(__file__))}/sample.wav', f'{sample_root}/sample.pt'
|
35 |
ffmpeg=f'{os.path.dirname(os.path.abspath(__file__))}/ffmpeg'
|
36 |
|
37 |
-
if tts is None:
|
38 |
-
# model_dir=os.environ.get("MODEL_DIR")
|
39 |
-
# model_path=model_dir
|
40 |
-
# config_path=f'{model_dir}/config.json'
|
41 |
-
# vocoder_config_path=f'{model_dir}/vocab.json'
|
42 |
-
model_name="tts_models/multilingual/multi-dataset/xtts_v2"
|
43 |
-
logging.info(f"loading model {model_name} ...")
|
44 |
-
tts = TTS(
|
45 |
-
model_name,
|
46 |
-
# model_path=model_path,
|
47 |
-
# config_path=config_path,
|
48 |
-
# vocoder_config_path=vocoder_config_path,
|
49 |
-
progress_bar=False
|
50 |
-
)
|
51 |
-
model=tts.synthesizer.tts_model
|
52 |
-
#hack to use cache
|
53 |
-
model.__get_conditioning_latents=model.get_conditioning_latents
|
54 |
-
model.get_conditioning_latents=get_conditioning_latents
|
55 |
-
logging.info("model is ready")
|
56 |
-
|
57 |
def predict(text, sample=None, language="zh"):
|
58 |
global tts
|
59 |
global model
|
60 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
text= re.sub("([^\x00-\x7F]|\w)(\.|\。|\?)",r"\1 \2\2",text)
|
62 |
wav = tts.tts(
|
63 |
text,
|
@@ -158,5 +157,5 @@ def trim_sample_audio(speaker_wav):
|
|
158 |
|
159 |
logging.info("xtts is ready")
|
160 |
|
161 |
-
import gradio as gr
|
162 |
-
gr.Interface(predict, inputs=["text", "text"], outputs=gr.Audio()).launch()
|
|
|
34 |
default_sample=f'{os.path.dirname(os.path.abspath(__file__))}/sample.wav', f'{sample_root}/sample.pt'
|
35 |
ffmpeg=f'{os.path.dirname(os.path.abspath(__file__))}/ffmpeg'
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
def predict(text, sample=None, language="zh"):
|
38 |
global tts
|
39 |
global model
|
40 |
try:
|
41 |
+
if tts is None:
|
42 |
+
# model_dir=os.environ.get("MODEL_DIR")
|
43 |
+
# model_path=model_dir
|
44 |
+
# config_path=f'{model_dir}/config.json'
|
45 |
+
# vocoder_config_path=f'{model_dir}/vocab.json'
|
46 |
+
model_name="tts_models/multilingual/multi-dataset/xtts_v2"
|
47 |
+
logging.info(f"loading model {model_name} ...")
|
48 |
+
tts = TTS(
|
49 |
+
model_name,
|
50 |
+
# model_path=model_path,
|
51 |
+
# config_path=config_path,
|
52 |
+
# vocoder_config_path=vocoder_config_path,
|
53 |
+
progress_bar=False
|
54 |
+
)
|
55 |
+
model=tts.synthesizer.tts_model
|
56 |
+
#hack to use cache
|
57 |
+
model.__get_conditioning_latents=model.get_conditioning_latents
|
58 |
+
model.get_conditioning_latents=get_conditioning_latents
|
59 |
+
logging.info("model is ready")
|
60 |
text= re.sub("([^\x00-\x7F]|\w)(\.|\。|\?)",r"\1 \2\2",text)
|
61 |
wav = tts.tts(
|
62 |
text,
|
|
|
157 |
|
158 |
logging.info("xtts is ready")
|
159 |
|
160 |
+
# import gradio as gr
|
161 |
+
# gr.Interface(predict, inputs=["text", "text"], outputs=gr.Audio()).launch()
|