Text-to-Speech
Transformers
ONNX
teratts_onnx
feature-extraction
onnxruntime
russian
english
custom-code
custom_code
Instructions to use TeraSpace/TeraTTSv2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TeraSpace/TeraTTSv2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-to-speech", model="TeraSpace/TeraTTSv2", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("TeraSpace/TeraTTSv2", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Expose normalized encoder text
Browse files- README.md +3 -0
- modeling_teratts.py +5 -0
- teratts.py +9 -4
README.md
CHANGED
|
@@ -57,6 +57,9 @@ tts.save_wav("teratts.wav", waveform)
|
|
| 57 |
`waveform` is a mono `float32` NumPy array at 44,100 Hz. `save_wav` writes
|
| 58 |
standard signed-16-bit PCM WAV without an extra audio package.
|
| 59 |
|
|
|
|
|
|
|
|
|
|
| 60 |
## Controls
|
| 61 |
|
| 62 |
| Control | Values | Effect |
|
|
|
|
| 57 |
`waveform` is a mono `float32` NumPy array at 44,100 Hz. `save_wav` writes
|
| 58 |
standard signed-16-bit PCM WAV without an extra audio package.
|
| 59 |
|
| 60 |
+
To inspect the exact text passed to the encoder after number expansion, stress
|
| 61 |
+
marking, and Unicode normalization, call `tts.normalize_text(text)`.
|
| 62 |
+
|
| 63 |
## Controls
|
| 64 |
|
| 65 |
| Control | Values | Effect |
|
modeling_teratts.py
CHANGED
|
@@ -18,6 +18,7 @@ from .teratts import (
|
|
| 18 |
generate_speech,
|
| 19 |
generate_speech_stream,
|
| 20 |
load_model,
|
|
|
|
| 21 |
write_wav,
|
| 22 |
)
|
| 23 |
|
|
@@ -122,6 +123,10 @@ class TeraTTSModel(PreTrainedModel):
|
|
| 122 |
seed=seed,
|
| 123 |
)
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
def generate_speech_stream(
|
| 126 |
self,
|
| 127 |
text: str,
|
|
|
|
| 18 |
generate_speech,
|
| 19 |
generate_speech_stream,
|
| 20 |
load_model,
|
| 21 |
+
normalize_text,
|
| 22 |
write_wav,
|
| 23 |
)
|
| 24 |
|
|
|
|
| 123 |
seed=seed,
|
| 124 |
)
|
| 125 |
|
| 126 |
+
def normalize_text(self, text: str) -> str:
|
| 127 |
+
"""Show the final tagged text passed to the TTS text encoder."""
|
| 128 |
+
return normalize_text(self._runtime(), text)
|
| 129 |
+
|
| 130 |
def generate_speech_stream(
|
| 131 |
self,
|
| 132 |
text: str,
|
teratts.py
CHANGED
|
@@ -101,6 +101,13 @@ def expand_tagged_numbers(text: str) -> str:
|
|
| 101 |
return LANGUAGE_TAG.sub(expand_span, text)
|
| 102 |
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
class UnicodeIndexer:
|
| 105 |
def __init__(self, indexer_path: Path):
|
| 106 |
self.table = json.loads(indexer_path.read_text())
|
|
@@ -360,10 +367,8 @@ def _generate_latent(
|
|
| 360 |
if style_ttl.shape != (1, 50, 256) or style_dp.shape != (1, 8, 16):
|
| 361 |
raise ValueError("style assets have unexpected shapes")
|
| 362 |
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
add_russian_stress(expanded_text, loaded.accentizer)
|
| 366 |
-
)
|
| 367 |
text_ids, text_mask = loaded.indexer.batch(model_text)
|
| 368 |
duration_ids, duration_mask = loaded.indexer.batch(duration_text)
|
| 369 |
text_emb = loaded.text_encoder.run(
|
|
|
|
| 101 |
return LANGUAGE_TAG.sub(expand_span, text)
|
| 102 |
|
| 103 |
|
| 104 |
+
def normalize_text(loaded: "LoadedTTS", text: str) -> str:
|
| 105 |
+
"""Return the exact text tensorized by the text encoder for an utterance."""
|
| 106 |
+
expanded_text = expand_tagged_numbers(text)
|
| 107 |
+
model_text, _ = prepare_raw_text(add_russian_stress(expanded_text, loaded.accentizer))
|
| 108 |
+
return model_text
|
| 109 |
+
|
| 110 |
+
|
| 111 |
class UnicodeIndexer:
|
| 112 |
def __init__(self, indexer_path: Path):
|
| 113 |
self.table = json.loads(indexer_path.read_text())
|
|
|
|
| 367 |
if style_ttl.shape != (1, 50, 256) or style_dp.shape != (1, 8, 16):
|
| 368 |
raise ValueError("style assets have unexpected shapes")
|
| 369 |
|
| 370 |
+
model_text = normalize_text(loaded, text)
|
| 371 |
+
duration_text = model_text.replace("+", "")
|
|
|
|
|
|
|
| 372 |
text_ids, text_mask = loaded.indexer.batch(model_text)
|
| 373 |
duration_ids, duration_mask = loaded.indexer.batch(duration_text)
|
| 374 |
text_emb = loaded.text_encoder.run(
|