Skip to content

pocket_tts: apply the config's replace_characters like the reference - #1339

Merged
0xShug0 merged 1 commit into
0xShug0:mainfrom
unaltolga:fix/pocket-tts-replace-characters
Nov 19, 2026
Merged

0xShug0 merged 1 commit into
0xShug0:mainfrom
unaltolga:fix/pocket-tts-replace-characters

Conversation

@unaltolga

Copy link
Copy Markdown
Contributor

What

PocketTTS configs can list characters that are absent from the training data, with what to replace each one by (replace_characters). pocket-tts applies the table in prepare_text_prompt before anything else. The audio.cpp PocketTTS runtime never read it, so these characters reached the tokenizer unchanged.

The published French package (PocketTTS-GGUF/french) embeds a config.yaml with this table: quotes and guillemets are deleted, ’ becomes ', : becomes ,, and brackets are deleted. With that package, main prepares:

Input main this PR (and the Python reference)
Il a dit : « Bonjour à tous » (en souriant). Il a dit : « Bonjour à tous » (en souriant). Il a dit , Bonjour à tous en souriant.
"Bonjour ?", a-t-elle demandé. "Bonjour ?", a-t-elle demandé. Bonjour ? a-t-elle demandé.
Le prix est [environ] 12 euros ; c’est cher. Le prix est [environ] 12 euros , c’est cher. Le prix est environ 12 euros , c'est cher.
« Où es-tu ? » demanda-t-il. « Où es-tu ? » demanda-t-il. Où es-tu ? demanda-t-il.

Changes

  • PocketTTSModelConfig / descriptor: new replace_characters, read from the replace_characters.* keys of the YAML config. A key that is not a single character throws, as str.maketrans would.
  • prepare_pocket_tts_text applies it right after the initial strip, as the reference does:
    • one translation pass, so each character is replaced once;
    • whitespace collapsed the way str.split() splits, including the no-break spaces French text has before : and inside guillemets;
    • a ,, ; or : right after ., !, ? or … is dropped. Deleting quotes turns "Bonjour ?", a-t-elle into Bonjour ?, a-t-elle, and the reference keeps only the sentence mark.
  • Both callers pass the table: TextConditioner::prepare and split_into_sentence_chunks. Every text route goes through prepare.
  • With text_chunk_size, the text is cut after the replacement step (new TextConditioner::apply_replace_characters). Otherwise a chunk made only of deleted characters, such as the closing » of a sentence, prepares to an empty prompt and fails. I checked chunk sizes 1, 2, 4, 8 and 12 in offline and streaming mode.
  • A prompt made only of deleted characters (« ») now fails with "text prompt cannot be empty", as the reference raises on it.

A config without the table takes the same path as before. That covers the built-in defaults, which the other language packages use because they embed only tokenizer.model. Gradium Phonon fills its config from config.json (parse_json("config") in gradium_phonon.cpp), so its table stays empty.

Validation

macOS 27.2 on an Apple M2, CPU backend (the Mac CI configuration: Debug, ENGINE_ENABLE_METAL=OFF), on 5e7273d, with PocketTTS-GGUF/french/pocket-tts-french-q8_0.gguf and the cosette voice.

  • Same text and token ids as the Python reference. I ran a small program on the public API (load_pocket_tts_assets and TextConditioner::prepare) over 8 French lines with guillemets, curly and straight quotes, brackets, :, … and no-break spaces. I compared it with pocket-tts prepare_text_prompt, called with the package's own embedded config and tokenizer.model. The prepared text and the token ids match on all 8 lines. On main, 7 of the 8 keep the characters.

  • YAML. The flattener reads the same table as PyYAML for the embedded French config and for the upstream english, french_24l, german, italian, portuguese and spanish configs ('''' values, ¡ and ¿ keys).

  • Runtime, before and after. I synthesized 16 French sentences containing guillemets, brackets and colons with audiocpp_cli, built from main and from this branch. Each sentence ran with seeds 1 to 8, so 128 WAVs per build. I transcribed them with Whisper small (mlx-community/whisper-small-asr-fp16, language=fr) and scored WER against the words to be spoken, lowercased with punctuation removed:

    Sentences main this PR
    all 16 (1,184 words) 46.5% 33.0%
    4 with brackets 66.0% 33.3%
    10 with guillemets 38.9% 34.0%
    2 with a colon only 42.1% 27.6%

    11 sentences improve, 4 get worse and 1 is unchanged. The absolute numbers are high for both builds: Whisper small is a weak French recognizer, and it writes numbers as digits ("9h" for "neuf heures"), which counts as errors on both sides. The comparison between the builds is the point here.

  • ctest: 113 of 117 pass from the build directory. The other 4 (parakeet_variant_config_test, lfm2_audio_assets_test, lfm3_audio_assets_test, model_spec_system_test) look for model_specs/ relative to the working directory, and my build directory is outside the checkout. They pass when run from the repository root.

  • No unit test is added. The text preparation sits in an anonymous namespace and needs the model's SentencePiece pieces, and pocket_tts: chunk text like the reference, UTF-8 aware text prep #671 and pocket_tts: honour capitalize_first_letter from config.yaml #1229 on this file were validated the same way, by runtime comparison.

  • Not covered: other languages, since their packages carry no config. Adding the upstream tables to the built-in defaults is a separate change. German also has remove_semicolons: true upstream, which the defaults set only for french_24l. I can send that next if it is wanted.

AI disclosure: written with Claude Code (Claude Opus 5.5). I reviewed the change, and the results above are from real runs on my Mac.

The PocketTTS configs list characters that are absent from the training data
and what to replace them with. The French package embeds such a config, but
the runtime never read the table, so guillemets, quotes, brackets and ":"
reached the tokenizer as they were.

Read replace_characters from the YAML config and apply it in
prepare_pocket_tts_text the way pocket_tts prepare_text_prompt does: one
translation pass, whitespace collapsed the way str.split() splits (no-break
spaces included), then a ",;:" right after a sentence mark is dropped.
With text_chunk_size the text is cut after this step, so a chunk made only of
deleted characters (a closing guillemet) cannot become an empty prompt.
Configs without the table behave as before.
@0xShug0
0xShug0 merged commit df60b9d into 0xShug0:main Nov 19, 2026
7 checks passed
@0xShug0

0xShug0 commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@unaltolga Thanks for the fix! PR merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants