Skip to content

A research project focused on developing a lightweight neural voice cloning and speech synthesis system, optimized for deployment on edge devices.

Python

Adjust max-pause value to 0.5s

IgorSwat751f64ff6436
diff --git a/docs/usage.md b/docs/usage.md
index 0aa58b7..b687f03 100644
--- a/docs/usage.md
+++ b/docs/usage.md
@@ -67,8 +67,8 @@ takes = [tts.generate(text, voice, language="en", seed=s) for s in range(4)] #
## Control the length
The length is estimated from the text and the reference's speaking rate. The rate counts only the time the
-reference spends speaking: its silent edges and any pause over 0.2 s are left out, so a recording with long pauses
-doesn't make the takes slow. The recording itself is used whole.
+reference spends speaking: its silent edges are left out and any pause over 0.5 s counts as 0.5 s, so a recording
+with long pauses doesn't make the takes slow. The recording itself is used whole.
`pace="recording"` estimates from the whole recording instead, pauses included, as earlier versions did.
```python
diff --git a/reverb_tts/audio.py b/reverb_tts/audio.py
index bed8072..0ee5ea2 100644
--- a/reverb_tts/audio.py
+++ b/reverb_tts/audio.py
@@ -63,7 +63,7 @@ def trim_silence(audio: np.ndarray, sample_rate: int, keep: float = 0.1) -> np.n
return audio[max(sounds[0][0] - margin, 0) * window: min(sounds[-1][-1] + 1 + margin, count) * window]
-def speech_length(audio: np.ndarray, sample_rate: int, max_pause: float = 0.2, lead: float = 0.1,
+def speech_length(audio: np.ndarray, sample_rate: int, max_pause: float = 0.5, lead: float = 0.1,
trail: float = 0.2) -> float:
"""
Seconds of a reference recording that set the speaker's pace: the recording without its silent edges (keeping
diff --git a/reverb_tts/tts.py b/reverb_tts/tts.py
index a89cc6b..dc47a07 100644
--- a/reverb_tts/tts.py
+++ b/reverb_tts/tts.py
@@ -218,7 +218,7 @@ class TTS:
- seed: the take's seed; consecutive seeds go to the pieces of a list or a long text. None draws one.
- speed: a factor on the estimated length. duration: the length in seconds, in place of the estimate.
- pace: the reference length the estimate follows. "speech" counts only the time the reference spends speaking
- (`Voice.speech_frames`: no silent edges, pauses capped at 0.2 s); "recording" counts the whole recording.
+ (`Voice.speech_frames`: no silent edges, pauses capped at 0.5 s); "recording" counts the whole recording.
- prepare: verbalize the text first (turn off for text that already is).
- trim: cut the take's silent edges.
- sampler, overrides: sampler settings for this call, e.g. steps=12 or remasking=False.
diff --git a/tests/test_audio.py b/tests/test_audio.py
index 71e4ec7..4127a26 100644
--- a/tests/test_audio.py
+++ b/tests/test_audio.py
@@ -40,10 +40,11 @@ def quiet(seconds: float) -> np.ndarray:
def test_speech_length_keeps_short_edges_and_caps_pauses() -> None:
- # 1 s of edge silence on each side, a 1.5 s and a 0.1 s pause between 1 s sounds.
- audio = np.concatenate([quiet(1), tone(1), quiet(1.5), tone(1), quiet(0.1), tone(1), quiet(1)])
- # 3 s of sound, the long pause counted as 0.2 s, the short one whole, and 0.1 s + 0.2 s of the edges.
- assert speech_length(audio, RATE) == pytest.approx(3 + 0.2 + 0.1 + 0.1 + 0.2, abs=0.02)
+ # 1 s of edge silence on each side, a 1.5 s and a 0.3 s pause between 1 s sounds.
+ audio = np.concatenate([quiet(1), tone(1), quiet(1.5), tone(1), quiet(0.3), tone(1), quiet(1)])
+ # 3 s of sound, the long pause counted as 0.5 s, the sentence-length one whole, and 0.1 s + 0.2 s of the edges.
+ assert speech_length(audio, RATE) == pytest.approx(3 + 0.5 + 0.3 + 0.1 + 0.2, abs=0.02)
+ assert speech_length(audio, RATE, max_pause=0.2) == pytest.approx(3 + 0.2 + 0.2 + 0.1 + 0.2, abs=0.02)
def test_speech_length_of_clean_speech_is_its_length() -> None:
@@ -53,7 +54,7 @@ def test_speech_length_of_clean_speech_is_its_length() -> None:
def test_speech_length_levels_a_quiet_recording_first() -> None:
# The whole recording sits under -50 dBFS, yet its sounds are told from its silence.
audio = np.concatenate([tone(1, 1e-4), quiet(2), tone(1, 1e-4)])
- assert speech_length(audio, RATE) == pytest.approx(2.2, abs=0.02)
+ assert speech_length(audio, RATE) == pytest.approx(2.5, abs=0.02)
def test_speech_length_counts_a_silent_or_tiny_recording_whole() -> None:
diff --git a/tests/test_tts.py b/tests/test_tts.py
index 487c6c3..3216745 100644
--- a/tests/test_tts.py
+++ b/tests/test_tts.py
@@ -43,7 +43,7 @@ def test_a_voice_measures_its_speech_and_keeps_the_recording_whole(tts: TTS) ->
silence = np.zeros(RATE, np.float32)
voice = tts.voice(np.concatenate([silence, sound, silence, sound, silence]), "Hello there.", "en", sample_rate=RATE)
assert voice.codes.size(1) == 125 # 5 s, nothing cut
- assert voice.speech_frames == pytest.approx(25 * 2.5, abs=1) # 2 s of sound, a 0.2 s pause, 0.1 + 0.2 s of edges
+ assert voice.speech_frames == pytest.approx(25 * 2.8, abs=1) # 2 s of sound, a 0.5 s pause, 0.1 + 0.2 s of edges
assert voice.pace_frames == voice.speech_frames