Skip to content

fishaudio: reuse streaming websocket and prebuffer initial chunks#2017

Open
rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
pilaw-glared-elisions
Open

fishaudio: reuse streaming websocket and prebuffer initial chunks#2017
rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
pilaw-glared-elisions

Conversation

@rosetta-livekit-bot

@rosetta-livekit-bot rosetta-livekit-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Port livekit-plugins-fishaudio pooled websocket reuse and initial audio prebuffering from livekit/agents#6368.

  • Reuse /v1/tts/live websocket connections through the existing JS ConnectionPool.
  • Add TTS.prewarm() and close pooled sockets from TTS.close().
  • Invalidate the pool when model changes because FishAudio sends model as a websocket handshake header.
  • Prebuffer the first two audio chunks before feeding the byte stream, flushing held audio on short utterance finish.

Source diff coverage

Coverage
Source file Classification Target handling
livekit-plugins/livekit-plugins-fishaudio/livekit/plugins/fishaudio/tts.py Ported/adapted Ported to plugins/fishaudio/src/tts.ts. The pooled /v1/tts/live websocket behavior maps to the existing JS ConnectionPool; prewarm(), pool close, model-change invalidation, and first-N chunk prebuffering were implemented. Adaptations are TypeScript/Node ws API differences, millisecond duration units (300_000 ms), and the target stream/frame queue conventions.

Verification

  • pnpm --filter @livekit/agents-plugin-fishaudio... build
  • pnpm --filter @livekit/agents-plugin-fishaudio build
  • pnpm --filter @livekit/agents-plugin-fishaudio lint
  • pnpm test -- plugins/fishaudio (FishAudio test skipped because FISH_API_KEY/OPENAI_API_KEY are not set)
  • pnpm build
  • pnpm lint (passes with pre-existing warnings in unrelated packages)
  • cue-cli text-mode run against built warm-transfer example: asserted conversation_item_added(.item.message.role="ASSISTANT"); FishAudio provider was not exercised because FISH_API_KEY is not set in this environment.

Notes

  • Target already had the needed ConnectionPool infrastructure, so no infrastructure gap was left unported.
  • pnpm --filter @livekit/agents-plugin-fishaudio api:check still fails due existing package API report/release-tag warnings (plugins/fishaudio/etc API report is absent); this PR does not introduce that gap.

Ported from livekit/agents#6368

Original PR description

two changes to the fish plugin:

  1. reuse/pre-warm the /v1/tts/live websocket via utils.ConnectionPool (same
    pattern as cartesia/rime). the plugin used to open a fresh WSS per utterance,
    paying ~330ms of TLS+WS handshake on every reply. now one socket is reused per
    session and pre-warmed via prewarm(), so the first reply skips the handshake.
    general latency win, independent of the crackle fix.

  2. prebuffer the first two audio chunks before starting playout. fish streams a
    small first chunk (~460ms) then, ~250ms later, a much larger second chunk.
    starting webrtc's real-time playout at the first chunk leaves only ~190ms of
    buffer headroom; app/network jitter tips it into an underrun the receiver
    conceals as an audible click/gap ~0.5s into the first utterance (repro'd ~1 in
    5). waiting for the second chunk starts playout with ~1.3s buffered and
    eliminates it.

the prebuffer is an internal constant (_PREBUFFER_CHUNKS = 2), not a public
option. it costs a little TTFB and is a stopgap for fish's cold-start chunk
pacing; once the inference side streams the opening chunks smoothly we'll drop it
to 1 to start on the first chunk. working with the fish inference team on that now.

verified no crackles on livekit-demo-web.onrender.com; chunk-2 headroom measured
before/after and the negative tail is gone.

@rosetta-livekit-bot rosetta-livekit-bot Bot requested a review from a team as a code owner July 10, 2026 06:40
@changeset-bot

changeset-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 363246c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 36 packages
Name Type
@livekit/agents-plugin-fishaudio Major
@livekit/agents Major
@livekit/agents-plugin-anam Major
@livekit/agents-plugin-anthropic Major
@livekit/agents-plugin-assemblyai Major
@livekit/agents-plugin-baseten Major
@livekit/agents-plugin-bey Major
@livekit/agents-plugin-cartesia Major
@livekit/agents-plugin-cerebras Major
@livekit/agents-plugin-deepgram Major
@livekit/agents-plugin-did Major
@livekit/agents-plugin-elevenlabs Major
@livekit/agents-plugin-google Major
@livekit/agents-plugin-hedra Major
@livekit/agents-plugin-hume Major
@livekit/agents-plugin-inworld Major
@livekit/agents-plugin-lemonslice Major
@livekit/agents-plugin-liveavatar Major
@livekit/agents-plugin-livekit Major
@livekit/agents-plugin-minimax Major
@livekit/agents-plugin-mistral Major
@livekit/agents-plugin-mistralai Major
@livekit/agents-plugin-neuphonic Major
@livekit/agents-plugin-openai Major
@livekit/agents-plugin-perplexity Major
@livekit/agents-plugin-phonic Major
@livekit/agents-plugin-resemble Major
@livekit/agents-plugin-rime Major
@livekit/agents-plugin-runway Major
@livekit/agents-plugin-sarvam Major
@livekit/agents-plugin-silero Major
@livekit/agents-plugin-soniox Major
@livekit/agents-plugin-tavus Major
@livekit/agents-plugin-trugen Major
@livekit/agents-plugin-xai Major
@livekit/agents-plugins-test Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

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.

0 participants