KokoroEngine wraps the Kokoro pipeline. It is a local neural engine with
language-code-aware voice selection, voice formulas, and timing support.
pip install "realtimetts[kokoro]"For extra language stacks, install the matching RealtimeTTS extras:
pip install "realtimetts[kokoro,jp,zh,ko]"Some non-English paths may also require OS-level espeak-ng support depending on the Kokoro package and platform.
from RealtimeTTS import TextToAudioStream, KokoroEngine
if __name__ == "__main__":
engine = KokoroEngine(voice="af_heart")
stream = TextToAudioStream(engine)
stream.feed("Hello from Kokoro.")
stream.play()- Default voice is
af_heart. - Voice prefixes determine language codes:
af/amAmerican English,bf/bmBritish English,jf/jmJapanese,zf/zmMandarin Chinese, plus Spanish, French, Hindi, Italian, and Brazilian Portuguese prefixes. - Weighted voice formulas such as
0.3*af_sarah + 0.7*am_adamare parsed and cached. - Important controls include
default_speed, silence trimming fields, anddebug. - Zaphod dev-log benchmarks found Kokoro among the fastest balanced local baselines in that environment.
- If a voice loads with the wrong language pipeline, pass a
KokoroVoicewith an explicitlanguage_code. - Missing language package errors usually mean the corresponding
jp,zh, orkoextras were not installed.