Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -38,31 +38,28 @@ def tts(text: str, voice: str = "Male", use_onnx: bool = True):
|
|
38 |
if len(text) > MAX_TXT_LEN:
|
39 |
text = text[:MAX_TXT_LEN]
|
40 |
print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
|
41 |
-
|
|
|
|
|
42 |
|
43 |
text = text.replace("I", "ӏ") # Replace capital "I" with "Palochka" symbol
|
44 |
text = text.lower()
|
45 |
|
46 |
if use_onnx:
|
47 |
-
# Load the ONNX model
|
48 |
onnx_model_url = MALE_ONNX_MODEL_URL if voice == "Male" else FEMALE_ONNX_MODEL_URL
|
49 |
|
50 |
config = VitsConfig()
|
51 |
-
config.load_json(
|
52 |
|
53 |
-
# Initialize the tokenizer
|
54 |
tokenizer = TTSTokenizer(
|
55 |
use_phonemes=False,
|
56 |
text_cleaner=config.text_cleaner,
|
57 |
-
characters=VitsCharacters(),
|
58 |
phonemizer=None,
|
59 |
add_blank=config.add_blank,
|
60 |
)
|
61 |
|
62 |
-
# Create the Vits model instance
|
63 |
vits = Vits.init_from_config(config)
|
64 |
-
|
65 |
-
# Load the ONNX model into the Vits model
|
66 |
vits.load_onnx(onnx_model_url)
|
67 |
|
68 |
text_inputs = np.asarray(
|
@@ -76,10 +73,9 @@ def tts(text: str, voice: str = "Male", use_onnx: bool = True):
|
|
76 |
out_path = temp_file.name
|
77 |
save_wav(wav=audio[0], path=out_path, sample_rate=24000)
|
78 |
else:
|
79 |
-
model_dir = BASE_DIR.format("male" if voice == "Male" else "female")
|
80 |
|
81 |
# Synthesize
|
82 |
-
synthesizer = Synthesizer(f"{model_dir}/model.pth",
|
83 |
wavs = synthesizer.tts(text)
|
84 |
|
85 |
# Create a temporary WAV file
|
|
|
38 |
if len(text) > MAX_TXT_LEN:
|
39 |
text = text[:MAX_TXT_LEN]
|
40 |
print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
|
41 |
+
|
42 |
+
model_dir = BASE_DIR.format("male" if voice == "Male" else "female")
|
43 |
+
config_file = f"{model_dir}/config.json"
|
44 |
|
45 |
text = text.replace("I", "ӏ") # Replace capital "I" with "Palochka" symbol
|
46 |
text = text.lower()
|
47 |
|
48 |
if use_onnx:
|
|
|
49 |
onnx_model_url = MALE_ONNX_MODEL_URL if voice == "Male" else FEMALE_ONNX_MODEL_URL
|
50 |
|
51 |
config = VitsConfig()
|
52 |
+
config.load_json(config_file)
|
53 |
|
|
|
54 |
tokenizer = TTSTokenizer(
|
55 |
use_phonemes=False,
|
56 |
text_cleaner=config.text_cleaner,
|
57 |
+
characters=VitsCharacters(),
|
58 |
phonemizer=None,
|
59 |
add_blank=config.add_blank,
|
60 |
)
|
61 |
|
|
|
62 |
vits = Vits.init_from_config(config)
|
|
|
|
|
63 |
vits.load_onnx(onnx_model_url)
|
64 |
|
65 |
text_inputs = np.asarray(
|
|
|
73 |
out_path = temp_file.name
|
74 |
save_wav(wav=audio[0], path=out_path, sample_rate=24000)
|
75 |
else:
|
|
|
76 |
|
77 |
# Synthesize
|
78 |
+
synthesizer = Synthesizer(f"{model_dir}/model.pth", config_file)
|
79 |
wavs = synthesizer.tts(text)
|
80 |
|
81 |
# Create a temporary WAV file
|