Skip to content

refactor(vad): store duration constants in ms instead of hops#1200

Merged
msluszniak merged 1 commit into
mainfrom
@ms/vad-duration-constants-ms
May 29, 2026
Merged

refactor(vad): store duration constants in ms instead of hops#1200
msluszniak merged 1 commit into
mainfrom
@ms/vad-duration-constants-ms

Conversation

@msluszniak
Copy link
Copy Markdown
Member

Description

kMinSpeechDuration, kMinSilenceDuration and kSpeechPad were stored as hop counts with trailing comments hinting the ms equivalent. The unit implicitly depended on kHopLengthMs, and the comments would rot the moment someone changed it.

Rename to *Ms to match the kWindowSizeMs / kHopLengthMs convention and convert to hops at the use site via / kHopLengthMs. Now kHopLengthMs changes propagate automatically and the source-of-truth unit is explicit in the name.

Introduces a breaking change?

  • Yes
  • No

Type of change

  • Bug fix (change which fixes an issue)
  • New feature (change which adds functionality)
  • Documentation update (improves or adds clarity to existing documentation)
  • Other (chores, tests, code style improvements etc.)

Tested on

  • iOS
  • Android

Testing instructions

Refactor only — values are unchanged (250 / 10 = 25, 100 / 10 = 10, 30 / 10 = 3). Existing VAD behavior should be identical.

Screenshots

Related issues

Closes #1172

Checklist

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Additional notes

Per discussion in the issue, picked option 2 (ms-based source of truth) over the rename-with-Hops-suffix option because it survives changes to kHopLengthMs.

kMinSpeechDuration, kMinSilenceDuration and kSpeechPad were stored as
hop counts with trailing comments hinting the ms equivalent. The unit
implicitly depended on kHopLengthMs, and the comments would rot if
kHopLengthMs ever changed.

Rename to *Ms and convert to hops at the use site by dividing by
kHopLengthMs, matching the kWindowSizeMs / kHopLengthMs convention used
elsewhere in the file.

Closes #1172
@msluszniak msluszniak self-assigned this May 28, 2026
Copy link
Copy Markdown
Contributor

@benITo47 benITo47 left a comment

Choose a reason for hiding this comment

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

Keeping the code clean I see.

@msluszniak msluszniak merged commit 778c507 into main May 29, 2026
4 checks passed
@msluszniak msluszniak deleted the @ms/vad-duration-constants-ms branch May 29, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VAD: duration constants use hop units while neighbours use ms

2 participants