Skip to content

A TTS that fits in your CPU (and pocket)

Python

Back to a 5 ms fade-in at chunk starts (#335)

manu-lm80d24a3ad3cb
diff --git a/pocket_tts/models/tts_model.py b/pocket_tts/models/tts_model.py
index 3f7d37b..7eb7c35 100644
--- a/pocket_tts/models/tts_model.py
+++ b/pocket_tts/models/tts_model.py
@@ -511,10 +511,10 @@ class TTSModel(nn.Module):
try:
audio_chunks = []
mimi_state = init_states(self.mimi, batch_size=1, sequence_length=mimi_sequence_length)
- # Each chunk starts with a fresh Mimi decoder state, which puts a small step in the first
- # samples, and with the first latent after BOS, which can decode to a burst of about 40 ms.
- # Both are heard as a click at every chunk start: fade the first frame (80 ms) in.
- fade_in: torch.Tensor | None = torch.linspace(0, 1, self.mimi.frame_size)
+ # A fresh Mimi decoder state puts a small step (about -41 dBFS) in its first samples, heard
+ # as a click at the start of every chunk: fade the first 5 ms in. (The longer burst some
+ # voices produced came from prompts ending on speech, handled by end_on_pause.)
+ fade_in: torch.Tensor | None = torch.linspace(0, 1, self.config.mimi.sample_rate // 200)
while True:
latent = latents_queue.get()
if latent is None:
diff --git a/tests/test_generation_regressions.py b/tests/test_generation_regressions.py
index d24a011..6f5972f 100644
--- a/tests/test_generation_regressions.py
+++ b/tests/test_generation_regressions.py
@@ -109,7 +109,7 @@ def test_is_safetensors_source_handles_revisions_and_query_strings(source: str,
def test_decode_audio_worker_fades_in_only_the_first_decoded_frame():
- # The first frame of each chunk can carry a click (decoder cold start, first latent after BOS).
+ # A fresh Mimi decoder state starts with a small step, heard as a click at every chunk start.
class FakeMimi(torch.nn.Module):
frame_size = 1920
@@ -128,6 +128,7 @@ def test_decode_audio_worker_fades_in_only_the_first_decoded_frame():
latents.put(item)
model._decode_audio_worker(latents, results, mimi_sequence_length=8, mimi_steps_per_latent=1)
first, second = results.get(timeout=5)[1], results.get(timeout=5)[1]
- assert torch.equal(first.flatten(), torch.linspace(0, 1, 1920))
+ assert torch.equal(first[0, 0, :120], torch.linspace(0, 1, 120))
+ assert torch.all(first[..., 120:] == 1.0)
assert torch.all(second == 1.0)
assert results.get() == ("done", None)