Spaces:
Sleeping
Sleeping
Text to audio
Browse files
model.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
from functools import lru_cache
|
|
|
|
|
|
|
| 2 |
from pathlib import Path
|
| 3 |
|
| 4 |
import sherpa_onnx
|
|
@@ -33,11 +35,20 @@ def get_pretrained_model(repo_id: str, speed: float) -> sherpa_onnx.OfflineTts:
|
|
| 33 |
filename="model.onnx",
|
| 34 |
subfolder="kokoro-en-v0_19",
|
| 35 |
)
|
| 36 |
-
|
| 37 |
repo_id=source_repo,
|
| 38 |
filename="tokens.txt",
|
| 39 |
subfolder="kokoro-en-v0_19",
|
| 40 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
voices = _get_file(
|
| 42 |
repo_id=source_repo,
|
| 43 |
filename="voices.bin",
|
|
@@ -66,4 +77,3 @@ def get_pretrained_model(repo_id: str, speed: float) -> sherpa_onnx.OfflineTts:
|
|
| 66 |
max_num_sentences=1,
|
| 67 |
)
|
| 68 |
return sherpa_onnx.OfflineTts(tts_config)
|
| 69 |
-
|
|
|
|
| 1 |
from functools import lru_cache
|
| 2 |
+
import os
|
| 3 |
+
import tempfile
|
| 4 |
from pathlib import Path
|
| 5 |
|
| 6 |
import sherpa_onnx
|
|
|
|
| 35 |
filename="model.onnx",
|
| 36 |
subfolder="kokoro-en-v0_19",
|
| 37 |
)
|
| 38 |
+
tokens_raw = _get_file(
|
| 39 |
repo_id=source_repo,
|
| 40 |
filename="tokens.txt",
|
| 41 |
subfolder="kokoro-en-v0_19",
|
| 42 |
)
|
| 43 |
+
|
| 44 |
+
# Sanitize tokens file to prevent parsing errors (e.g. empty lines)
|
| 45 |
+
with open(tokens_raw, "r", encoding="utf-8") as f:
|
| 46 |
+
lines = [line for line in f if line.strip()]
|
| 47 |
+
|
| 48 |
+
fd, tokens = tempfile.mkstemp(suffix=".txt", text=True)
|
| 49 |
+
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
| 50 |
+
f.writelines(lines)
|
| 51 |
+
|
| 52 |
voices = _get_file(
|
| 53 |
repo_id=source_repo,
|
| 54 |
filename="voices.bin",
|
|
|
|
| 77 |
max_num_sentences=1,
|
| 78 |
)
|
| 79 |
return sherpa_onnx.OfflineTts(tts_config)
|
|
|