Skip to content

SOTA-Class TTS at Compact Scale

Python

Prevent empty first frame in 0.1B ONNX runtime

chuarunyuan6bdc912cc374
diff --git a/onnx_runtime_0_1b_int8/arktts_runtime/runtime.py b/onnx_runtime_0_1b_int8/arktts_runtime/runtime.py
index c9b2952..c84e5be 100644
--- a/onnx_runtime_0_1b_int8/arktts_runtime/runtime.py
+++ b/onnx_runtime_0_1b_int8/arktts_runtime/runtime.py
@@ -351,6 +351,13 @@ class ArkTtsRuntime:
raise ValueError("this runtime only supports relative_semantic_then_eos logits")
if values.size != expected:
raise ValueError(f"unexpected slow logits size: {values.size}, expected {expected}")
+ if not previous:
+ # A sampled EOS at the voice prompt boundary produces no codec frame
+ # and used to surface as an HTTP 500 from ``synthesize``. The first
+ # frame is always required for a valid TTS result; EOS remains
+ # available on every subsequent step.
+ values = values.copy()
+ values[-1] = -np.inf
normal_index = _sample(values, temperature, top_p, top_k, rng)
high_index = _sample(values, 1.0, 0.9, top_k, rng)
normal = stop if normal_index == expected - 1 else begin + normal_index
diff --git a/onnx_runtime_0_1b_int8/tests/test_sampling.py b/onnx_runtime_0_1b_int8/tests/test_sampling.py
index 5d5c3e1..2c98e2b 100644
--- a/onnx_runtime_0_1b_int8/tests/test_sampling.py
+++ b/onnx_runtime_0_1b_int8/tests/test_sampling.py
@@ -2,7 +2,7 @@ from __future__ import annotations
import numpy as np
-from arktts_runtime.runtime import _sample
+from arktts_runtime.runtime import ArkTtsRuntime, _sample
def test_sample_uses_gumbel_max_noise() -> None:
@@ -16,3 +16,35 @@ def test_sample_uses_gumbel_max_noise() -> None:
rng=np.random.default_rng(0),
)
assert result == 0
+
+
+def test_first_semantic_step_cannot_return_eos() -> None:
+ runtime = object.__new__(ArkTtsRuntime)
+ runtime.manifest = {
+ "codebook_size": 2,
+ "semantic_begin_id": 100,
+ "semantic_end_id": 101,
+ "im_end_id": 4096,
+ "slow_logits_layout": "relative_semantic_then_eos",
+ }
+ logits = np.asarray([0.0, 1.0, 100.0], dtype=np.float32)
+
+ first = runtime._sample_semantic(
+ logits,
+ previous=[],
+ temperature=1.0,
+ top_p=1.0,
+ top_k=1,
+ rng=np.random.default_rng(0),
+ )
+ assert first == 101
+
+ later = runtime._sample_semantic(
+ logits,
+ previous=[first],
+ temperature=1.0,
+ top_p=1.0,
+ top_k=1,
+ rng=np.random.default_rng(0),
+ )
+ assert later == 4096