A TTS that fits in your CPU (and pocket)
Python
Fade in the whole first frame of each chunk (#333)
manu-lma3325b19fd4d
diff --git a/pocket_tts/models/tts_model.py b/pocket_tts/models/tts_model.pyindex 4535ce0..2c10f2c 100644--- a/pocket_tts/models/tts_model.py+++ b/pocket_tts/models/tts_model.py@@ -511,9 +511,10 @@ class TTSModel(nn.Module):try:audio_chunks = []mimi_state = init_states(self.mimi, batch_size=1, sequence_length=mimi_sequence_length)- # 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.- fade_in: torch.Tensor | None = torch.linspace(0, 1, self.config.mimi.sample_rate // 200)+ # 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)while True:latent = latents_queue.get()if latent is None:diff --git a/tests/test_generation_regressions.py b/tests/test_generation_regressions.pyindex ba18d65..d24a011 100644--- a/tests/test_generation_regressions.py+++ b/tests/test_generation_regressions.py@@ -109,8 +109,10 @@ def test_is_safetensors_source_handles_revisions_and_query_strings(source: str,def test_decode_audio_worker_fades_in_only_the_first_decoded_frame():- # A fresh Mimi decoder state starts with a small step, heard as a click at every chunk start.+ # The first frame of each chunk can carry a click (decoder cold start, first latent after BOS).class FakeMimi(torch.nn.Module):+ frame_size = 1920+def decode_from_latent(self, latent: torch.Tensor, state: object) -> torch.Tensor:return torch.ones(1, 1, 1920 * latent.shape[1])@@ -125,7 +127,7 @@ def test_decode_audio_worker_fades_in_only_the_first_decoded_frame():for item in (torch.zeros(1, 1, 32), torch.zeros(1, 1, 32), None):latents.put(item)model._decode_audio_worker(latents, results, mimi_sequence_length=8, mimi_steps_per_latent=1)- first, second = results.get()[1], results.get()[1]- assert first[..., 0].item() == 0.0 and first[..., 119].item() == 1.0- assert torch.all(first[..., 120:] == 1.0) and torch.all(second == 1.0)+ first, second = results.get(timeout=5)[1], results.get(timeout=5)[1]+ assert torch.equal(first.flatten(), torch.linspace(0, 1, 1920))+ assert torch.all(second == 1.0)assert results.get() == ("done", None)