Skip to content

fix(rt): don't assume a default audio format#119

Draft
sam-s10s wants to merge 1 commit into
mainfrom
pr/rt-audio-format
Draft

fix(rt): don't assume a default audio format#119
sam-s10s wants to merge 1 commit into
mainfrom
pr/rt-audio-format

Conversation

@sam-s10s

@sam-s10s sam-s10s commented Jul 20, 2026

Copy link
Copy Markdown
Member

Summary

The RT AsyncClient previously initialised _audio_format to a hardcoded default (PCM_S16LE, 44.1 kHz, 4096-byte chunks). If audio_seconds_sent (or anything relying on the format) was consulted before start_session supplied a real format, it silently computed against those wrong defaults.

This PR makes the audio format explicit:

  • _audio_format starts as None and is only set once start_session resolves an explicit AudioFormat (the resolved value is captured back from _start_recognition_session).
  • audio_seconds_sent now raises a ValueError if called before start_session, instead of returning a value derived from a 44.1 kHz assumption.

Why

Silently defaulting to 44.1 kHz produced subtly wrong audio_seconds_sent values (and therefore timing) for clients that hadn't yet started a session or used a different rate. Failing loudly is safer.

Notes

  • Behavioural change for any consumer that read audio_seconds_sent/the format before start_session — they now get an explicit error rather than a wrong number.
  • Extracted from the voice/v0.2.9-rc3 pre-release line as one of several focused PRs.

Test plan

  • RT unit tests pass
  • Confirm audio_seconds_sent behaves correctly after start_session at 8/16/44.1 kHz

Set _audio_format to None until start_session resolves an explicit format
(instead of hardcoding 44.1kHz PCM). audio_seconds_sent now raises if called
before start_session rather than computing against wrong defaults.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant