fix(rt): don't assume a default audio format#119
Draft
sam-s10s wants to merge 1 commit into
Draft
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The RT
AsyncClientpreviously initialised_audio_formatto a hardcoded default (PCM_S16LE, 44.1 kHz, 4096-byte chunks). Ifaudio_seconds_sent(or anything relying on the format) was consulted beforestart_sessionsupplied a real format, it silently computed against those wrong defaults.This PR makes the audio format explicit:
_audio_formatstarts asNoneand is only set oncestart_sessionresolves an explicitAudioFormat(the resolved value is captured back from_start_recognition_session).audio_seconds_sentnow raises aValueErrorif called beforestart_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_sentvalues (and therefore timing) for clients that hadn't yet started a session or used a different rate. Failing loudly is safer.Notes
audio_seconds_sent/the format beforestart_session— they now get an explicit error rather than a wrong number.voice/v0.2.9-rc3pre-release line as one of several focused PRs.Test plan
audio_seconds_sentbehaves correctly afterstart_sessionat 8/16/44.1 kHz