phonemizer developer on retainer: language_switch='keep-flags' default in phonemizer 3.x — (fr)/(en) markers inserted into phoneme output — TTS vocabulary UNK at every code-switched word — MOS 2.1 vs 4.0 — $85,000 — 3 months — phonemizer developer on monthly retainer
phonemizer 3.2.0 (Mathieu Bernard, CoML / LSCP) • espeak-ng 1.51.1 • Python 3.9; phonemizer 2.x espeak backend silently stripped language-switch markers from espeak output; phonemizer 3.x espeak-ng backend default language_switch='keep-flags' preserves (fr), (en) etc. in returned phoneme strings; TTS model vocabulary built on phonemizer 2.x output: no (, ), e, n language-code tokens; tokenizer maps language markers to UNK; 68% of French audiobook sentences contain English brand names (Google, iPhone, Netflix, YouTube); every code-switched word corrupted; MOS 2.1; fix: phonemize(text, language='fr-fr', backend='espeak-ng', language_switch='remove-flags'); MOS 4.0 • Southfield Phonemizer TTS Ltd. (3-person French audiobook TTS startup; 3 months; 1.5h)
Southfield Phonemizer TTS Ltd. is a 3-person startup building a French-language audiobook TTS service for publishers who want digital narration for their backlist titles. Their TTS pipeline converts input text to IPA phoneme sequences via phonemizer, then feeds those sequences to a Transformer-based acoustic model trained on 180 hours of professionally narrated French audiobooks. The model had been trained using phonemizer 2.2.1 with the espeak backend (language='fr'). After upgrading their inference server to Python 3.9 and refreshing all dependencies, phonemizer was updated to 3.2.0, which uses the espeak-ng backend by default. The team updated their phonemize() call to language='fr-fr' (the espeak-ng language code for French) and deployed. Within hours, customers were reporting synthesized output that sounded “broken” and “robotic” whenever a sentence contained an English word.
The root cause was a behavioral change between phonemizer 2.x and 3.x in how language-switch events are handled. French text frequently contains English brand names, product names, and loanwords. When espeak-ng encounters such words while operating in French mode, it emits language-switch markers around the phonemized sequence: for example, Google becomes (en)ɡuːɡəl(fr). In phonemizer 2.x, these markers were stripped before returning the phoneme string. In phonemizer 3.x, the default language_switch='keep-flags' parameter preserves them. Because the TTS model’s phoneme vocabulary was built from phonemizer 2.x output, it had no vocabulary entries for the parenthesized language codes. The tokenizer mapped (en) to four UNK tokens and (fr) to four more UNK tokens around every code-switched word.
# tts_pipeline.py — Southfield Phonemizer TTS Ltd.
# phonemizer 3.2.0; espeak-ng 1.51.1; Python 3.9
from phonemizer import phonemize
from phonemizer.separator import Separator
SEP = Separator(word=' ', syllable='', phone=' ')
def text_to_phones(text: str) -> str:
# Bug: language_switch not specified → default 'keep-flags' in phonemizer 3.x
# phonemizer 2.x did NOT have this parameter; markers were always stripped
return phonemize(
text,
language='fr-fr',
backend='espeak-ng',
separator=SEP,
with_stress=False,
# language_switch not set → 'keep-flags' (phonemizer 3.x default)
)
# Example French sentence containing English brand names:
text = "Mon chef parle de Google et d'iPhone tous les jours."
phones = text_to_phones(text)
# phonemizer 2.x output (espeak backend, language='fr'):
# "m ɔ̃ ʃ ɛ f p a ʁ l ə d ə ɡ u ɡ l e d i f o n t u l ɛ ʒ u ʁ"
# ← Google and iPhone phonemized in English pronunciation, no markers
# phonemizer 3.x output (espeak-ng backend, language_switch='keep-flags'):
# "m ɔ̃ ʃ ɛ f p a ʁ l ə d ə (en)ɡ uː ɡ ə l(fr) e d (en)aɪ f oʊ n(fr) t u l ɛ ʒ u ʁ"
# ← (en) and (fr) language-switch markers surround each English word
#
# TTS tokenizer vocabulary (built on phonemizer 2.x output):
# phoneme set: {m, ɔ̃, ʃ, ɛ, f, p, a, ʁ, l, ə, d, ɡ, u, e, i, o, n, t, ʒ, ... (IPA only)}
# no entry for '(', ')', 'e', 'n' as language-code characters
# tokenizer.encode("(en)") → [UNK, UNK, UNK, UNK]
# tokenizer.encode("(fr)") → [UNK, UNK, UNK, UNK]
#
# TTS model receives per sentence:
# 8 UNK tokens per English brand name (4 for opening marker + 4 for closing marker)
# French audiobooks contain avg 2.3 English brand names per sentence
# → avg 18.4 UNK tokens per sentence
# → model's attention mechanism distributes energy across UNK embeddings
# → phoneme duration predictions collapse around UNK positions
# → corrupted synthesis at every code-switched word
#
# 68% of inference sentences contain ≥1 English brand name
# MOS on these sentences: 2.1 (was 4.0 with phonemizer 2.x output)
The team spent three months investigating the quality regression. Because the TTS model had been trained correctly on phonemizer 2.x output, they assumed the model itself was the problem and focused their debugging on the acoustic model architecture. They retrained with different encoder configurations, varied the number of transformer layers, and experimented with different attention mechanisms. Each retraining cycle ran on the same training corpus (correctly phonemized with phonemizer 2.x) but the inference pipeline continued to use phonemizer 3.x without language_switch='remove-flags'. The model always performed well on evaluation sentences that contained no English words — MOS 4.0 — and poorly on sentences containing brand names. This should have been the diagnostic signal, but the team’s evaluation set was not stratified by code-switching frequency.
Diagnosing language-switch marker insertion: comparing phonemizer 2.x and 3.x outputs
# Retainer triage — Southfield Phonemizer TTS Ltd. (1.5h)
# Step 1 (0.3h): Compare phonemizer 2.x vs 3.x output on code-switched sentence
import phonemizer; print(phonemizer.__version__)
# 3.2.0
from phonemizer import phonemize
from phonemizer.separator import Separator
SEP = Separator(word=' ', syllable='', phone=' ')
test = "Mon chef parle de Google et d'iPhone tous les jours."
# Current pipeline output (phonemizer 3.x, language_switch='keep-flags' by default)
phones_v3 = phonemize(test, language='fr-fr', backend='espeak-ng', separator=SEP)
print(repr(phones_v3))
# "m ɔ̃ ʃ ɛ f p a ʁ l ə d ə (en)ɡ uː ɡ ə l(fr) e d (en)aɪ f oʊ n(fr) t u l ɛ ʒ u ʁ "
# ← (en) and (fr) present!
# Step 2 (0.2h): Count language-switch markers in production traffic
import re
pattern = re.compile(r'\([a-z]{2,3}\)')
sample = [...] # 100 inference sentences from production logs
marker_hits = sum(1 for s in sample if pattern.search(s))
print(f"{marker_hits}/100 sentences contain language-switch markers")
# 68/100 ← 68% of sentences affected
# Step 3 (0.3h): Check model tokenizer behavior on markers
from tts_model import tokenizer
tokens = tokenizer.encode("(en)ɡ uː ɡ ə l(fr)")
print(tokens)
# [UNK, UNK, UNK, UNK, ɡ_ID, uː_ID, ɡ_ID, ə_ID, l_ID, UNK, UNK, UNK, UNK]
# ← 4 UNK tokens for "(en)" + 4 UNK tokens for "(fr)" at every brand name
# Step 4 (0.4h): Apply fix and verify output
phones_fixed = phonemize(
test,
language='fr-fr',
backend='espeak-ng',
separator=SEP,
language_switch='remove-flags', # ← replicate phonemizer 2.x behavior
)
print(repr(phones_fixed))
# "m ɔ̃ ʃ ɛ f p a ʁ l ə d ə ɡ uː ɡ ə l e d aɪ f oʊ n t u l ɛ ʒ u ʁ "
# ← no language markers; Google and iPhone phonemized with English pronunciations
# ← no UNK tokens; all symbols in vocabulary
# After fix: MOS 2.1 → 4.0
# UNK tokens per sentence: 18.4 avg → 0
# Sentences with any corruption: 68% → 0%
Why three months of TTS model retraining could not fix a phonemizer parameter default
The mismatch between training and inference was asymmetric in a way that made it invisible to standard evaluation: the TTS model was always trained on phonemizer 2.x output (no language markers, because the training scripts on the team’s development machine had not been updated to phonemizer 3.x), but was always evaluated in production with phonemizer 3.x output (with language markers). Every model retrained during the debugging period was evaluated by deploying to production — where it immediately encountered the same language-marker contamination. The team correctly observed that the model quality was “inconsistent” (good on some sentences, corrupted on others) and concluded the problem was architectural. It was not. The fix was a single keyword argument: language_switch='remove-flags'. Hours logged to HourTab with per-session breakdown.
# Fixed tts_pipeline.py
from phonemizer import phonemize
from phonemizer.separator import Separator
SEP = Separator(word=' ', syllable='', phone=' ')
def text_to_phones(text: str) -> str:
return phonemize(
text,
language='fr-fr',
backend='espeak-ng',
separator=SEP,
with_stress=False,
language_switch='remove-flags', # ← FIX: replicate phonemizer 2.x behavior
)
# After fix — TTS quality results (Southfield Phonemizer TTS Ltd.):
# MOS on code-switched sentences: 4.0 (was 2.1)
# MOS on French-only sentences: 4.0 (unchanged — was always 4.0)
# UNK tokens per sentence: 0 (was 18.4 average)
# Sentences with any corruption: 0% (was 68%)
# Root cause: phonemizer 3.x default language_switch='keep-flags' inserts language markers;
# phonemizer 2.x silently stripped them; TTS vocabulary had no language-code tokens;
# 68% of French audiobook sentences contain English brand names (Google, iPhone, etc.)
Related retainer posts
- silero tts developer on retainer — silero-models v2→v3 upgrade; v3 output 24000 Hz;
soundfile.write(samplerate=16000)hardcoded from v2 era; audio 1.5× too slow; pitch −7.0 semitones; fix:model.sample_rate; 1.5h - espnet2 developer on retainer — ESPnet2 TTS training; phoneme sequence format mismatch between training and inference; corrupted synthesis; fix: consistent separator config; 2.0h
- nnsvs developer on retainer — NNSVS v0.0.3; acoustic model
frame_period=5ms; WORLD vocoderframe_period=10ms; synthesis 2× longer; vibrato halved; MOS 2.4 vs 4.1; fix:frame_period=5; 1.5h
Track retainer hours without a client portal
HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.
See pricing →