Repository navigation
Feature/fonadalabs livekit agent - #8322
Pragyanshu-Fonada wants to merge 39 commits into
Conversation
Refactor error handling to maintain exception context.
"fetch latest chnages from upstream "
- STT: new Kapture V3 plugin (POST /v3/asr/transcribe), 11 languages incl. Odia - TTS: Klone V2 Flash streams over a pooled WebSocket; Klone V2 Pro uses /v1/voice-clone/chunks - Voices are selected by Voice Arena share_id (required); voice-name catalog removed - Reconnect transparently when a pooled TTS WebSocket was closed by the server - Language lists match the FonadaLabs docs / API (Flash 12, Pro 48) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sync with upstream 1.8.10. Resolved livekit-agents/pyproject.toml by taking upstream and re-adding the fonadalabs extra; plugin bumped to 1.8.10 and its pyproject aligned with the current plugin template. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Note
Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.
Devin Review found 3 potential issues.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| self._tts._chunks_url, | ||
| data=data, | ||
| headers={"Authorization": f"Bearer {self._tts._api_key}"}, | ||
| timeout=aiohttp.ClientTimeout(total=max(self._conn_options.timeout, 60.0)), |
There was a problem hiding this comment.
i think this is valid, and going by the ~2.4s per 100 chars in the comment, a full 5000-char chunk would take ~120s, so the 60s floor wouldn't cover it either. maybe we could respect conn_options.timeout and note in the readme that Pro needs a higher tts_conn_options timeout, or at least logger.warning when we raise it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…loor Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tinalenguyen
left a comment
There was a problem hiding this comment.
hi, thanks for the PR! few notes:
- could you resolve the merge conflicts and regenerate the uv.lock file? main is at 1.8.12 now, so the plugin version and the
livekit-agentsfloors should start there too (left suggestions inline) - could we have
LiveKitas the author and fill out the pyproject accordingly (example)
1. flash TTS waits for the whole LLM reply before speaking — tts.py:314
async for data in self._input_ch:
if isinstance(data, self._FlushSentinel):
break
parts.append(data)the voice pipeline pushes LLM tokens into tts.stream() as they arrive and only calls end_input() after the last one (voice/agent.py, tts_node). _run doesn't send anything to the socket until that flush, so time to first audio becomes the full LLM generation time plus the TTS TTFB, which can be several seconds on longer replies. since the plugin declares streaming=True, the framework also won't wrap it in a sentence-level StreamAdapter, so nothing else splits the text either. text pushed after the first flush is dropped too, since the loop breaks and never reads the channel again
let's run the input through a sentence tokenizer and send each sentence over the socket once it's complete, like cartesia does with tokenize.blingfire.SentenceTokenizer. if the 10 requests/minute limit counts every ws message, maybe we could send the first sentence on its own and batch the rest, so the first audio still goes out early
2. pooled socket can carry stale audio into the next reply — tts.py:355
on an APIStatusError mid-utterance the socket goes back to the pool whenever it's still open. the request_id check in _speak_ws only applies to TEXT frames, and BINARY frames are pushed unconditionally (tts.py:399). so if the server has audio frames for the failed request in flight when it sends {"type": "error"}, the next reply plays them first. that's the leak the comment at tts.py:336 says the pool avoids. let's remove the socket on any error mid-utterance, same as the timeout path
| # _run may be retried; the input channel can only be consumed once. | ||
| if self._text is None: | ||
| parts: list[str] = [] | ||
| async for data in self._input_ch: |
There was a problem hiding this comment.
this waits for the whole LLM reply before sending anything, more details in the summary
| except APIStatusError: | ||
| reusable = not ws.closed # server keeps the socket open after an error | ||
| raise |
There was a problem hiding this comment.
i think we should drop the socket on any error here, otherwise in-flight audio from the failed request can play in the next reply
| except APIStatusError: | |
| reusable = not ws.closed # server keeps the socket open after an error | |
| raise |
| mime_type="audio/pcm", | ||
| ) | ||
|
|
||
| # _run may be retried; the input channel can only be consumed once. |
There was a problem hiding this comment.
small nit: the base class replays the buffered input into a fresh _input_ch before each retry, so i don't think we need to cache _text here
|
|
||
| # Per-request text limit for both Klone V2 models. | ||
| _MAX_TEXT_CHARS = 5000 | ||
| _SENTENCE_SPLIT_RE = re.compile(r"(?<=[।.!?\n])\s*") |
There was a problem hiding this comment.
small nit: this splits on every period even without a following space (3.50 → 3. 50), could we use tokenize.basic.split_sentences instead?
| api_key: str | None = None, | ||
| model: TTSModels | str = "klone_v2_flash", | ||
| language: TTSFlashLanguages | str = "hi", | ||
| instruct: str | None = None, | ||
| num_step: int | None = None, | ||
| speed: float | None = None, |
There was a problem hiding this comment.
could we use NotGivenOr for api_key, instruct, num_step and speed so they match update_options?
|
|
||
| [project.urls] | ||
| Documentation = "https://docs.livekit.io" | ||
| Website = "https://fonada.in/" |
There was a problem hiding this comment.
| Website = "https://fonada.in/" | |
| Website = "https://livekit.io/" |
| @@ -0,0 +1 @@ | |||
| __version__ = "1.8.10" | |||
There was a problem hiding this comment.
| __version__ = "1.8.10" | |
| __version__ = "1.8.12" |
| fal = ["livekit-plugins-fal>=1.8.10"] | ||
| fishaudio = ["livekit-plugins-fishaudio>=1.8.10"] | ||
| fireworksai = ["livekit-plugins-fireworksai>=1.8.10"] | ||
| fonadalabs = ["livekit-plugins-fonadalabs>=1.8.10"] |
There was a problem hiding this comment.
| fonadalabs = ["livekit-plugins-fonadalabs>=1.8.10"] | |
| fonadalabs = ["livekit-plugins-fonadalabs>=1.8.12"] |
| | `klone_v2_flash` (default) | WebSocket `wss://api.fonada.ai/v1/voice-clone/ws` | 12 | Streaming, lowest latency, ₹6 / 10K chars | | ||
| | `klone_v2_pro` | HTTPS `POST /v1/voice-clone/chunks` | 48 | Higher quality, no streaming, ₹60 / 10K chars | |
There was a problem hiding this comment.
could we drop the pricing from this table? it'll go stale in the readme
| | `kn` | Kannada | `te` | Telugu | | ||
| | `ml` | Malayalam | | | | ||
|
|
||
| ## Documentation |
There was a problem hiding this comment.
could we add a link to the LiveKit docs page here too? (pending a release)
Sync with 1.8.12: plugin version and livekit-agents floors start at 1.8.12, pyproject follows the LiveKit plugin template (LiveKit as author), and uv.lock is regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Run streamed text through a sentence tokenizer (blingfire by default, configurable via tokenizer=). The first sentence is sent on its own so audio starts before the LLM reply is finished; sentences that arrive meanwhile are batched into the next request to stay within the 10 requests/minute limit. Applies to both Flash (WebSocket) and Pro (HTTP). - Keep reading the input channel after a flush instead of dropping later text. - Remove the pooled WebSocket after any error mid-utterance so in-flight audio of a failed request can't play at the start of the next reply. - Drop the cached _text: the base class replays input on retry. - Split long text with LiveKit's sentence tokenizer instead of a regex (no more splitting "3.50"). - api_key, instruct, num_step and speed use NotGivenOr, matching update_options. - README: remove pricing, link the LiveKit integration docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- _connect_ws closes the socket on any failure while waiting for the ready message, including cancellation, since it is not in the pool yet. - Pro requests are split at sentence boundaries into chunks of at most 1000 chars. Pro generates the whole clip before responding (~2.4s per 100 chars), so a large batch could exceed the 60s request timeout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Regenerate uv.lock after upstream lockfile changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bump the plugin to 1.8.13 with the release and regenerate uv.lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@tinalenguyen thanks again for the review! All feedback is addressed:
The only remaining conflict is Could you take another look when you have a moment? Thanks! |
Resolve livekit-agents/pyproject.toml and uv.lock conflicts, bump livekit-plugins-fonadalabs to 1.9.0 and regenerate uv.lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Pro: warn once when raising the request timeout to 60s; document tts_conn_options for klone_v2_pro in the README - TTS update_options: warn when num_step is set on klone_v2_pro - STT: use KAPTURE_LANGUAGES directly, add update_options(language=...) - Docstring: Kapture V3 only - pyproject: support@livekit.io author, add aiohttp>=3.9.0 dependency Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve uv.lock conflict by regenerating it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @tinalenguyen , gentle reminder All your review comments are addressed and the branch is up to date with main. Could you please take another look when you get a chance? |
Title: Add FonadaLabs plugin (Kapture V3 STT + Klone V2 TTS)
Adds
livekit-plugins-fonadalabs, a plugin for FonadaLabs speech APIs focused on Indian languages.share_idand can be changed withupdate_options().Outside the plugin folder: one workspace entry in
pyproject.tomland onefonadalabsextra inlivekit-agents/pyproject.toml.Testing (livekit-agents 1.8.10):
ruffand strictmypypass.