Repository navigation
pocket_tts: apply the config's replace_characters like the reference - #1339
Merged
0xShug0 merged 1 commit intoNov 19, 2026
Merged
Conversation
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.
Owner
|
@unaltolga Thanks for the fix! PR merged. |
This was referenced Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inprepare_text_promptbefore 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 aconfig.yamlwith this table: quotes and guillemets are deleted,’becomes',:becomes,, and brackets are deleted. With that package, main prepares: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: newreplace_characters, read from thereplace_characters.*keys of the YAML config. A key that is not a single character throws, asstr.maketranswould.prepare_pocket_tts_textapplies it right after the initial strip, as the reference does:str.split()splits, including the no-break spaces French text has before:and inside guillemets;,,;or:right after.,!,?or…is dropped. Deleting quotes turns"Bonjour ?", a-t-elleintoBonjour ?, a-t-elle, and the reference keeps only the sentence mark.TextConditioner::prepareandsplit_into_sentence_chunks. Every text route goes throughprepare.text_chunk_size, the text is cut after the replacement step (newTextConditioner::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.« ») 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 fromconfig.json(parse_json("config")ingradium_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), on5e7273d, withPocketTTS-GGUF/french/pocket-tts-french-q8_0.ggufand thecosettevoice.Same text and token ids as the Python reference. I ran a small program on the public API (
load_pocket_tts_assetsandTextConditioner::prepare) over 8 French lines with guillemets, curly and straight quotes, brackets,:,…and no-break spaces. I compared it with pocket-ttsprepare_text_prompt, called with the package's own embedded config andtokenizer.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,portugueseandspanishconfigs (''''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: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 formodel_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: trueupstream, which the defaults set only forfrench_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.