Feat/add chunk size control arg (#56)

This pull request addresses issue #38 

**Changes included:**

- Added a `max_tokens` parameter to the typer cli for the `generate`
command, allowing user to set a default number of tokens per chunk.
- Introduced a default variable `MAX_TOKEN_PER_CHUNK` to centralize the
default value.
- Fixed a tokenization issue by inserting a comma, allowing the model to
correctly read each chunk as intended rather than treating one chunk as
a single sentence.

**Future improvement suggestion :**

- Consider enhancing the `split_into_best_sentences` function using
regex to split text more accurately without modifying it, which would
improve clarity and maintainability.

---------

Co-authored-by: Václav Volhejn <8401624+vvolhejn@users.noreply.github.com>
This commit is contained in:
Saleem Djima
2026-01-21 11:54:53 +01:00
committed by GitHub
co-authored by Václav Volhejn
parent 36f21a0a7f
commit 4ec89acf95
4 changed files with 16 additions and 4 deletions
+5
View File
@@ -22,6 +22,7 @@ from pocket_tts.default_parameters import (
DEFAULT_NOISE_CLAMP,
DEFAULT_TEMPERATURE,
DEFAULT_VARIANT,
MAX_TOKEN_PER_CHUNK,
)
from pocket_tts.models.tts_model import TTSModel
from pocket_tts.utils.logging_utils import enable_logging
@@ -223,6 +224,9 @@ def generate(
str, typer.Option(help="Output path for generated audio")
] = "./tts_output.wav",
device: Annotated[str, typer.Option(help="Device to use")] = "cpu",
max_tokens: Annotated[
int, typer.Option(help="Maximum number of tokens per chunk.")
] = MAX_TOKEN_PER_CHUNK,
):
"""Generate speech using Kyutai Pocket TTS."""
if "cuda" in device:
@@ -242,6 +246,7 @@ def generate(
model_state=model_state_for_voice,
text_to_generate=text,
frames_after_eos=frames_after_eos,
max_tokens=max_tokens,
)
stream_audio_chunks(output_path, audio_chunks, tts_model.config.mimi.sample_rate)