Skip to content

feat(sarvam): expose max_session_duration as TTS constructor parameter#5430

Open
KeWang0622 wants to merge 1 commit intolivekit:mainfrom
KeWang0622:fix/sarvam-tts-max-session-duration
Open

feat(sarvam): expose max_session_duration as TTS constructor parameter#5430
KeWang0622 wants to merge 1 commit intolivekit:mainfrom
KeWang0622:fix/sarvam-tts-max-session-duration

Conversation

@KeWang0622
Copy link
Copy Markdown

Summary

Closes #5268

The Sarvam TTS plugin's WebSocket connection pool hardcodes max_session_duration to 3600 seconds, making it impossible to control connection reuse without reaching into private attributes (tts._pool._max_session_duration = 0).

This PR exposes max_session_duration as a public constructor parameter on sarvam.TTS:

tts = sarvam.TTS(
    target_language_code="hi-IN",
    model="bulbul:v3",
    speaker="ritu",
    max_session_duration=0,  # fresh connection per request
)

Changes:

  • Add max_session_duration field to SarvamTTSOptions dataclass (default: 3600)
  • Add max_session_duration parameter to TTS.__init__() with validation (>= 0)
  • Pass the value through to utils.ConnectionPool instead of the hardcoded 3600
  • Update docstrings for both the dataclass and the constructor

Behavior:

  • max_session_duration=3600 (default) — existing behavior, connections reused for up to 1 hour
  • max_session_duration=0 — fresh WebSocket per request, no reuse (may improve audio quality as noted in the issue)
  • max_session_duration=N — custom reuse window in seconds

No breaking changes — the default matches the previous hardcoded value.

Test plan

  • Verify sarvam.TTS(target_language_code="hi-IN", max_session_duration=0) creates a fresh connection per request
  • Verify default behavior (no max_session_duration arg) is unchanged
  • Verify max_session_duration=-1 raises ValueError
  • ruff check and ruff format pass

The WebSocket connection pool's max_session_duration was hardcoded to
3600 seconds, forcing connection reuse across all TTS requests. Users
who need a fresh connection per request (e.g. to avoid audio quality
degradation from stale server-side session state) had to reach into
private attributes.

Add max_session_duration as a public constructor parameter on
sarvam.TTS, with the same default (3600s). Setting it to 0 gives a
fresh WebSocket per request.

Closes livekit#5268
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

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 2 additional findings.

Open in Devin Review

@KeWang0622
Copy link
Copy Markdown
Author

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.

[sarvam] Expose max_session_duration as a constructor parameter to control WebSocket connection reuse

3 participants