lalalic commited on
Commit
af81852
·
verified ·
1 Parent(s): 0ca767b

Update xtts.py

Browse files
Files changed (1) hide show
  1. xtts.py +18 -22
xtts.py CHANGED
@@ -5,7 +5,6 @@ import torch
5
  import traceback
6
  import numpy as np
7
  import scipy
8
- from importlib import import_module
9
  from TTS.api import TTS
10
  from flask import Flask, Blueprint, request, jsonify, send_file
11
 
@@ -28,6 +27,8 @@ from qili import upload_bytes
28
  # else:
29
  # app = Blueprint("xtts", __name__)
30
 
 
 
31
 
32
  sample_root= os.environ.get('XTTS_SAMPLE_DIR')
33
  if(sample_root==None):
@@ -38,8 +39,21 @@ if not os.path.exists(sample_root):
38
  default_sample=f'{os.path.dirname(os.path.abspath(__file__))}/sample.wav', f'{sample_root}/sample.pt'
39
  ffmpeg=f'{os.path.dirname(os.path.abspath(__file__))}/ffmpeg'
40
 
41
- tts=None
42
- model=None
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  @app.route("/convert")
44
  def predict():
45
  global tts
@@ -55,22 +69,6 @@ def predict():
55
  text= re.sub("([^\x00-\x7F]|\w)(\.|\。|\?)",r"\1 \2\2",text)
56
 
57
  try:
58
- if tts is None:
59
- TTS=import_module("TTS.api").TTS
60
- model_name="tts_models/multilingual/multi-dataset/xtts_v2"
61
- logging.info(f"loading model {model_name} ...")
62
- tts = TTS(
63
- model_path=model_path,
64
- config_path=config_path,
65
- vocoder_config_path=vocoder_config_path,
66
- progress_bar=False
67
- )
68
- model=tts.synthesizer.tts_model
69
- #hack to use cache
70
- model.__get_conditioning_latents=model.get_conditioning_latents
71
- model.get_conditioning_latents=get_conditioning_latents
72
- logging.info("model is ready")
73
-
74
  wav = tts.tts(
75
  text,
76
  language=language if language is not None else "zh",
@@ -157,6 +155,4 @@ def trim_sample_audio(speaker_wav):
157
  traceback.print_exc()
158
  return speaker_wav
159
 
160
- for key, value in os.environ.items():
161
- logging.info(f"{key}: {value}")
162
- loggin.info("xtts is ready")
 
5
  import traceback
6
  import numpy as np
7
  import scipy
 
8
  from TTS.api import TTS
9
  from flask import Flask, Blueprint, request, jsonify, send_file
10
 
 
27
  # else:
28
  # app = Blueprint("xtts", __name__)
29
 
30
+ tts=None
31
+ model=None
32
 
33
  sample_root= os.environ.get('XTTS_SAMPLE_DIR')
34
  if(sample_root==None):
 
39
  default_sample=f'{os.path.dirname(os.path.abspath(__file__))}/sample.wav', f'{sample_root}/sample.pt'
40
  ffmpeg=f'{os.path.dirname(os.path.abspath(__file__))}/ffmpeg'
41
 
42
+ if tts is None:
43
+ model_name="tts_models/multilingual/multi-dataset/xtts_v2"
44
+ logging.info(f"loading model {model_name} ...")
45
+ tts = TTS(
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
  @app.route("/convert")
58
  def predict():
59
  global tts
 
69
  text= re.sub("([^\x00-\x7F]|\w)(\.|\。|\?)",r"\1 \2\2",text)
70
 
71
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  wav = tts.tts(
73
  text,
74
  language=language if language is not None else "zh",
 
155
  traceback.print_exc()
156
  return speaker_wav
157
 
158
+ logging.info("xtts is ready")