Skip to content

Feature/fonadalabs livekit agent - #8322

Open
Pragyanshu-Fonada wants to merge 39 commits into
livekit:mainfrom
Pragyanshu-Fonada:feature/fonadalabs_livekit_agent
Open

Pragyanshu-Fonada wants to merge 39 commits into
livekit:mainfrom
Pragyanshu-Fonada:feature/fonadalabs_livekit_agent

Conversation

@Pragyanshu-Fonada

Copy link
Copy Markdown

Title: Add FonadaLabs plugin (Kapture V3 STT + Klone V2 TTS)

Adds livekit-plugins-fonadalabs, a plugin for FonadaLabs speech APIs focused on Indian languages.

  • STT, Kapture V3: 11 languages (en, bn, gu, hi, kn, ml, mr, or, pa, ta, te). Each utterance is buffered with VAD and transcribed with one REST request.
  • TTS, Klone V2 Flash (default): streams over a pooled WebSocket in 12 languages.
  • TTS, Klone V2 Pro: one HTTP request per reply, 48 languages.
  • Voices are selected by Voice Arena share_id and can be changed with update_options().
stt=fonadalabs.STT(language="hi"),
tts=fonadalabs.TTS(share_id="UFNPsnEd", language="hi"),

Outside the plugin folder: one workspace entry in pyproject.toml and one fonadalabs extra in livekit-agents/pyproject.toml.

Testing (livekit-agents 1.8.10):

  • ruff and strict mypy pass.
  • Live API round trip passed 33/33. Flash TTS generated speech in all 11 Kapture languages and Kapture V3 transcribed it back correctly. Pro was tested in hi, en and or.

Pragyanshu-Fonada and others added 28 commits December 11, 2025 15:38
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>
@Pragyanshu-Fonada
Pragyanshu-Fonada requested a review from a team as a code owner November 2, 2026 13:43

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Devin Review

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)),

@devin-ai-integration devin-ai-integration Bot Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Pro synthesis ignores shorter timeouts

When conn_options.timeout is below 60 seconds, _run_http waits up to 60 seconds for a Pro response. Slow requests stall speech beyond the caller's deadline.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Pragyanshu-Fonada and others added 3 commits November 2, 2026 21:34
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…loor

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@tinalenguyen tinalenguyen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-agents floors should start there too (left suggestions inline)
  • could we have LiveKit as 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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this waits for the whole LLM reply before sending anything, more details in the summary

Comment on lines +354 to +356
except APIStatusError:
reusable = not ws.closed # server keeps the socket open after an error
raise

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Suggested change
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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*")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit: this splits on every period even without a following space (3.50 → 3. 50), could we use tokenize.basic.split_sentences instead?

Comment on lines +128 to +133
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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Website = "https://fonada.in/"
Website = "https://livekit.io/"

@@ -0,0 +1 @@
__version__ = "1.8.10"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__version__ = "1.8.10"
__version__ = "1.8.12"

Comment thread livekit-agents/pyproject.toml Outdated
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"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fonadalabs = ["livekit-plugins-fonadalabs>=1.8.10"]
fonadalabs = ["livekit-plugins-fonadalabs>=1.8.12"]

Comment on lines +49 to +50
| `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 |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we drop the pricing from this table? it'll go stale in the readme

| `kn` | Kannada | `te` | Telugu |
| `ml` | Malayalam | | |

## Documentation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we add a link to the LiveKit docs page here too? (pending a release)

Pragyanshu-Fonada and others added 2 commits November 17, 2026 03:00
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>
devin-ai-integration[bot]

This comment was marked as resolved.

Pragyanshu-Fonada and others added 3 commits November 17, 2026 03:08
- _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>
devin-ai-integration[bot]

This comment was marked as resolved.

@Pragyanshu-Fonada

Copy link
Copy Markdown
Author

@tinalenguyen thanks again for the review! All feedback is addressed:

  • Flash and Pro TTS now stream by sentence: first audio starts before the LLM reply finishes (first sentence sent alone, the rest batched to stay within the 10 req/min limit)
  • Pooled socket is dropped on any error mid-utterance (also verified with barge-in interruptions)
  • Retries rely on the base class input replay; NotGivenOr args; tokenizer-based text splitting
  • Version and livekit-agents floor match main (1.8.13), LiveKit as author, pricing removed, docs links added

The only remaining conflict is uv.lock, which changes on main almost daily. I'll regenerate it as soon as you're happy with the code, or feel free to run uv lock before merging (maintainer edits are enabled).

Could you take another look when you have a moment? Thanks!

Pragyanshu-Fonada and others added 2 commits November 27, 2026 11:45
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>
@Pragyanshu-Fonada

Copy link
Copy Markdown
Author

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?
Thanks

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants