Resolved

Kokoro TTS fails with mixed Japanese and English video generation

Python
TTS
Video Generation
Kokoro TTS
WhisperX
MoviePy
Multilingual
Localization

Video generation system couldn't handle dual-language segments (Japanese TEXT/PHILO + English CODE) due to hardcoded language settings | Missing Japanese font support and environment overrides caused rendering failures

Issue

The video generation pipeline failed to handle mixed-language scripts, where Japanese segments (e.g., TEXT/PHILO) rendered as unreadable glyph boxes (□□□), while English segments (e.g., CODE) worked correctly. Attempts to switch languages during text-to-speech (TTS) generation caused crashes due to mismatched phoneme models. The system was hardcoded for English and lacked support for Japanese language processing, including dynamic language switching, multilingual font rendering, and environment-specific configurations.

Culprit

  1. Hardcoded Language Processing: The system defaulted to English TTS and lacked the ability to dynamically switch languages for different script segments. This resulted in Japanese characters being rendered incorrectly and TTS generation failing with phoneme model mismatches.
  2. Font Limitations: The pipeline only supported ASCII fonts, which did not include Japanese character sets (e.g., kanji, hiragana, katakana). This caused missing glyphs and unreadable text in Japanese segments.
  3. Environment Configuration: The system did not support language-specific environment variables or overrides, preventing customization of voice settings and font configurations for Japanese content.
  4. Missing Dedicated Watcher: There was no specialized processing system for Japanese videos, leading to gaps in automation for multilingual content.

Solution

  1. Dynamic Language Switching: Implemented a system to detect the language required for each script segment (e.g., Japanese for TEXT/PHILO, English for CODE) and dynamically recreate the TTS pipeline with the appropriate phoneme model for each language.
  2. Japanese Font Integration: Updated the font system to include Japanese character sets (e.g., Noto Sans CJK) and adjusted font sizing to accommodate full-width characters, ensuring proper rendering of Japanese text.
  3. Multilingual Environment Support: Added a mechanism to load language-specific environment configurations (e.g., japanese.env) with custom voice settings and font adjustments for Japanese content.
  4. Dedicated Japanese Watcher: Introduced a specialized watcher system (JapaneseScriptWatcher) for processing Japanese videos, including support for multilingual series detection, high-resolution output, and GPU resource management.

Result: The system now correctly processes mixed-language scripts, dynamically switching between English and Japanese TTS, rendering Japanese characters properly, and supporting dedicated automation for Japanese video content.