Add Kokoro TTS plugin (server-mode, via Kokoro-FastAPI)#6409
Open
HenryVarro666 wants to merge 1 commit into
Open
Add Kokoro TTS plugin (server-mode, via Kokoro-FastAPI)#6409HenryVarro666 wants to merge 1 commit into
HenryVarro666 wants to merge 1 commit into
Conversation
Adds livekit-plugins-kokoro: a native TTS plugin for the open-weight Kokoro model served by Kokoro-FastAPI. Requests raw PCM (24 kHz mono s16le) with stream=true and forwards chunks through AudioEmitter as they arrive, instead of going through the OpenAI compatibility layer, whose SSE response parsing is incompatible with Kokoro-FastAPI's raw binary streaming for every model name except tts-1/tts-1-hd (fixes livekit#6184). Supports voice selection and Kokoro voice blending syntax, speed, lang_code, optional bearer auth for proxied deployments, a list_voices() helper, and update_options(). Hermetic tests included (local aiohttp fake server).
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.
Adds
livekit-plugins-kokoro: a native TTS plugin for the open-weight Kokoro model served by Kokoro-FastAPI. Fixes #6184.Why a native plugin (root cause of #6184)
The
openai.TTSadapter selects its stream parser by model name: onlytts-1/tts-1-hduse the raw-audio path; everything else — including the defaultgpt-4o-mini-ttsand the natural choicemodel="kokoro"— sendsstream_format="sse"and parses the response withiter_lines(), only pushing audio fromdata: {"type": "speech.audio.delta", ...}events. Kokoro-FastAPI ignores the unknownstream_formatfield (pydanticextra=ignore) and streams raw binary, so no line ever matches, zero frames are pushed, and the framework raisesAPIError: no audio frames were pushed— exactly what #6184 reports. Reproduced against a live Kokoro-FastAPI v0.6.0:The plugin requests
response_format="pcm", stream=true(raw 24 kHz mono s16le — Kokoro-FastAPI's sample rate is fixed server-side) and pushes chunks throughAudioEmitterwithmime_type="audio/pcm"as they arrive.Relation to #1615
#1615 (@kailashsp) runs Kokoro in-process via
kokoro-onnx, and was parked on the shared-inference-process direction davidzhao mentioned there. This PR is complementary, not a replacement: it is server-mode only — an HTTP client with zero in-process inference — so that architectural direction doesn't apply. It follows the same shape as the other HTTP vendor TTS plugins.Features
"af_bella(2)+af_sky(1)"),speed,lang_codelist_voices()helper (handles both the current and legacy response shapes)update_options(), optional bearer token for deployments behind an authenticating proxy (Kokoro-FastAPI itself needs none),KOKORO_BASE_URLenv varstreaming=Falsecapability — Kokoro-FastAPI takes complete text, so the framework's StreamAdapter handles sentence streamingTesting
Hermetic tests in
tests/test_plugin_kokoro_tts.py(pytest --plugin kokoro, no real server or key needed — a localaiohttpfake serves the endpoints): PCM passthrough byte-exactness, request-body correctness,update_options/lang_code, HTTP error →APIErrormapping,list_voicesboth shapes. 4/4 pass.Live verification against
ghcr.io/remsky/kokoro-fastapi-gpu:v0.6.0(H100): audio artifact plays correctly, voice blending produces distinct waveforms, 68 voices listed. To try it locally:make lint/ruff format --check/mypy(strict) all pass.Note on
uv.lock: besides the new package entries, the diff picks up a pending re-lock from an earlier dependency change onmain(phonic0.32.5 → 0.32.9,primp/lxmlpruned) — anyuv lockrun reproduces this. Happy to drop it and let you re-lock separately if preferred.