TeraSpace commited on
Commit
68fd114
·
verified ·
1 Parent(s): e370e93

Expose normalized encoder text

Browse files
Files changed (3) hide show
  1. README.md +3 -0
  2. modeling_teratts.py +5 -0
  3. 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
- expanded_text = expand_tagged_numbers(text)
364
- model_text, duration_text = prepare_raw_text(
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(