Spaces:
Sleeping
Sleeping
Update TTS server backend and model weights via upload script
Browse files
app.py
CHANGED
|
@@ -20,7 +20,7 @@ BASE_DIR = Path(__file__).resolve().parent
|
|
| 20 |
DEFAULT_MODEL = BASE_DIR / "models" / "lumua.onnx"
|
| 21 |
SAMPLE_RATE = 22050
|
| 22 |
VOCAB_SIZE = 10000
|
| 23 |
-
MAX_CHARS =
|
| 24 |
|
| 25 |
BOS_ID = 1
|
| 26 |
EOS_ID = 2
|
|
@@ -90,7 +90,7 @@ def get_session(model_path: str) -> ort.InferenceSession:
|
|
| 90 |
|
| 91 |
|
| 92 |
def split_text(text: str, max_chars: int = MAX_CHARS) -> list[str]:
|
| 93 |
-
sentences = re.split(r"(?<=[.!?
|
| 94 |
chunks = []
|
| 95 |
for sentence in sentences:
|
| 96 |
sentence = sentence.strip()
|
|
@@ -111,6 +111,20 @@ def split_text(text: str, max_chars: int = MAX_CHARS) -> list[str]:
|
|
| 111 |
return chunks
|
| 112 |
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
def synthesize(text, speed, pause, model_path):
|
| 115 |
if not text or not text.strip():
|
| 116 |
raise gr.Error("Please enter some text.")
|
|
@@ -129,7 +143,7 @@ def synthesize(text, speed, pause, model_path):
|
|
| 129 |
continue
|
| 130 |
tokens = np.array([ids], dtype=np.int64)
|
| 131 |
wav = session.run(None, {"tokens": tokens, "speed": speed_arr})[0]
|
| 132 |
-
pieces.append(np.asarray(wav, dtype=np.float32).squeeze())
|
| 133 |
pieces.append(gap)
|
| 134 |
elapsed = time.perf_counter() - start
|
| 135 |
|
|
|
|
| 20 |
DEFAULT_MODEL = BASE_DIR / "models" / "lumua.onnx"
|
| 21 |
SAMPLE_RATE = 22050
|
| 22 |
VOCAB_SIZE = 10000
|
| 23 |
+
MAX_CHARS = 600 # per chunk, keeps each call well under the ~510 token limit
|
| 24 |
|
| 25 |
BOS_ID = 1
|
| 26 |
EOS_ID = 2
|
|
|
|
| 90 |
|
| 91 |
|
| 92 |
def split_text(text: str, max_chars: int = MAX_CHARS) -> list[str]:
|
| 93 |
+
sentences = re.split(r"(?<=[.!?])\s+", text.strip())
|
| 94 |
chunks = []
|
| 95 |
for sentence in sentences:
|
| 96 |
sentence = sentence.strip()
|
|
|
|
| 111 |
return chunks
|
| 112 |
|
| 113 |
|
| 114 |
+
FADE = int(SAMPLE_RATE * 0.01)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def fade_edges(x: np.ndarray) -> np.ndarray:
|
| 118 |
+
n = min(FADE, len(x) // 2)
|
| 119 |
+
if n == 0:
|
| 120 |
+
return x
|
| 121 |
+
x = x.copy()
|
| 122 |
+
ramp = np.linspace(0.0, 1.0, n, dtype=np.float32)
|
| 123 |
+
x[:n] *= ramp
|
| 124 |
+
x[-n:] *= ramp[::-1]
|
| 125 |
+
return x
|
| 126 |
+
|
| 127 |
+
|
| 128 |
def synthesize(text, speed, pause, model_path):
|
| 129 |
if not text or not text.strip():
|
| 130 |
raise gr.Error("Please enter some text.")
|
|
|
|
| 143 |
continue
|
| 144 |
tokens = np.array([ids], dtype=np.int64)
|
| 145 |
wav = session.run(None, {"tokens": tokens, "speed": speed_arr})[0]
|
| 146 |
+
pieces.append(fade_edges(np.asarray(wav, dtype=np.float32).squeeze()))
|
| 147 |
pieces.append(gap)
|
| 148 |
elapsed = time.perf_counter() - start
|
| 149 |
|