Skip to content

fix(sarvam): request word timestamps on the REST recognize path - #6935

Open
devbm7 wants to merge 2 commits into
livekit:mainfrom
devbm7:fix/sarvam-timestamps-input-audio-codec
Open

fix(sarvam): request word timestamps on the REST recognize path#6935
devbm7 wants to merge 2 commits into
livekit:mainfrom
devbm7:fix/sarvam-timestamps-input-audio-codec

Conversation

@devbm7

@devbm7 devbm7 commented Aug 20, 2026

Copy link
Copy Markdown

Summary

  • _recognize_impl never sent Sarvam's with_timestamps field, so the timestamps block the response parser already handles never came back from the API β€” start_time/end_time silently fell back to a buffer-duration estimate instead of real word timing. Now requested whenever the model isn't on the legacy /speech-to-text-translate endpoint (gated via a new _model_supports_timestamps helper, mirroring the existing _model_supports_mode/_model_supports_vad_params pattern).

(An earlier revision of this PR also deprecated input_audio_codec, based on an incomplete reading of Sarvam's changelog. That's been reverted: Sarvam's docs confirm PCM formats β€” which is what this plugin's streaming path always sends β€” still require explicit codec declaration even after codec auto-detection became the default for self-describing formats like wav/mp3. So input_audio_codec is left untouched.)

Test plan

  • ruff format --check / ruff check clean
  • mypy strict clean
  • uv run pytest livekit-plugins/livekit-plugins-sarvam/tests/ β€” new test_timestamps_model_gating.py passes; existing test_speech_timing.py unaffected. (Note: test_language_probability.py has 16 pre-existing failures on main unrelated to this change β€” an AttributeError on _pending_eos in the SpeechStream.__new__ test-bypass pattern β€” not touched by this PR.)

REST recognize() never sent Sarvam's with_timestamps field, so the
timestamps block the response parser already handles never came back
and start_time/end_time silently fell back to a buffer-duration
estimate. Now requested whenever the model isn't on the legacy
translate endpoint.

Sarvam removed server-side support for input_audio_codec in January
2026 (the API now negotiates it automatically); the plugin now warns
when it's passed and no longer sends or acts on it, while keeping the
parameter in both signatures for backward compatibility.
@devbm7
devbm7 requested a review from a team as a code owner August 20, 2026 21:59
@CLAassistant

CLAassistant commented Aug 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

πŸ’‘ Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 944b3b4e42

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with πŸ‘.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

self._audio_encoding = self._opts.input_audio_codec or "audio/wav"
# input_audio_codec is deprecated and never forwarded (see STT.__init__/stream());
# always report the actual wire format we send.
self._audio_encoding = "audio/wav"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve PCM encoding for streaming audio

When a caller uses streaming with input_audio_codec="pcm_s16le"/pcm_l16/pcm_raw, _process_audio still sends raw int16 frame bytes, but this change now forces every audio message to claim audio/wav and also stops putting the selected codec in the WebSocket URL. That regresses the only path that let raw PCM streams be described correctly; those bytes are not WAV containers, so Sarvam can receive mislabeled/unlabeled audio for callers that previously configured the codec.

Useful? React with πŸ‘Β / πŸ‘Ž.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

the streaming api has already been deprecated by sarvam but yes we should introduce this once it is shelved

The legacy streaming audio message schema documents `encoding` as a
required per-chunk field, and Sarvam's PCM formats (which is what
_process_audio always sends β€” raw int16 samples, never a real WAV
container) still require explicit codec declaration even after the
January 2026 change that made codec auto-detection the default for
self-describing formats (wav, mp3, etc). Deprecating input_audio_codec
was based on an incomplete reading of that changelog entry and would
have made every stream mislabel its audio as audio/wav regardless of
what the caller actually sends.
@devbm7 devbm7 changed the title fix(sarvam): request word timestamps, deprecate input_audio_codec fix(sarvam): request word timestamps on the REST recognize path Aug 20, 2026
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