Skip to content

fix: normalize Silero waveforms before device transfer - #3

Merged
KalebJS merged 1 commit into
KalebJS:mainfrom
weypro:main
Apr 7, 2026
Merged

KalebJS merged 1 commit into
KalebJS:mainfrom
weypro:main

Conversation

@weypro

@weypro weypro commented Apr 7, 2026 •

Copy link
Copy Markdown

Silero was calling .to(device) on waveforms that still arrived as NumPy arrays through the MLX pipeline, which caused the 'numpy.ndarray' object has no attribute 'to' failure. Normalize waveforms to torch tensors before device transfer.

Summary by CodeRabbit

  • Bug Fixes
    • Strengthened audio processing pipeline with improved data handling and standardized conversion methods throughout preprocessing and detection stages. Ensures better compatibility with diverse audio input formats, various device configurations, and multiple audio source types, delivering more consistent and reliable speech detection performance across a wider range of use cases.

Silero was calling `.to(device)` on waveforms that still arrived as
NumPy arrays through the MLX pipeline, which caused the
`'numpy.ndarray' object has no attribute 'to'` failure. Normalize
waveforms to torch tensors before device transfer.
@coderabbitai

coderabbitai Bot commented Apr 7, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The Silero VAD module is updated to consistently convert audio waveforms to PyTorch float32 tensors during preprocessing and inference. The __call__ method now enforces dtype conversion when processing audio, and preprocess_audio standardizes all outputs to float32 regardless of input type.

Changes

Cohort / File(s) Summary
Silero VAD Type Standardization
whispermlx/vads/silero.py
Modified __call__ to coerce audio waveforms to float32 tensors before processing. Updated preprocess_audio to consistently return float32 tensors for both tensor and non-tensor inputs, replacing the prior behavior of returning inputs unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A whisper through the tensor stream,
Float32 dreams in unified scheme,
No more mixed types to cause dismay,
Just standardized waveforms all the way!
—Hop, skip, and type-cast away! 🎵

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: normalizing Silero waveforms to PyTorch tensors before device transfer to resolve the numpy array error.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
whispermlx/vads/silero.py (1)

44-47: Consolidate normalization in __call__ via preprocess_audio.

Line 45-47 only normalizes non-tensor inputs, while preprocess_audio now defines the canonical float32 behavior for both input types. Reusing it here avoids divergence and keeps normalization logic in one place.

Proposed refactor
-        waveform = audio["waveform"]
-        if not torch.is_tensor(waveform):
-            waveform = torch.as_tensor(waveform, dtype=torch.float32)
+        waveform = self.preprocess_audio(audio["waveform"])

         timestamps = self.get_speech_timestamps(
-            waveform.to(self.device),
+            waveform.to(self.device),
             model=self.vad_pipeline,
             sampling_rate=sample_rate,

Also applies to: 49-49

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@whispermlx/vads/silero.py` around lines 44 - 47, In __call__, the waveform
normalization is done conditionally for non-tensors; instead call the existing
preprocess_audio helper to canonicalize dtype/normalization for both tensor and
non-tensor inputs: replace the conditional block that touches waveform in
__call__ (and the similar occurrence around the second occurrence at lines
referenced) with a call to preprocess_audio(audio) (or the appropriate helper
method used in this module) and use its returned waveform; ensure you update
references to waveform to use the value returned by preprocess_audio and remove
the duplicate dtype/torch.as_tensor logic so all normalization lives in
preprocess_audio.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@whispermlx/vads/silero.py`:
- Around line 44-47: In __call__, the waveform normalization is done
conditionally for non-tensors; instead call the existing preprocess_audio helper
to canonicalize dtype/normalization for both tensor and non-tensor inputs:
replace the conditional block that touches waveform in __call__ (and the similar
occurrence around the second occurrence at lines referenced) with a call to
preprocess_audio(audio) (or the appropriate helper method used in this module)
and use its returned waveform; ensure you update references to waveform to use
the value returned by preprocess_audio and remove the duplicate
dtype/torch.as_tensor logic so all normalization lives in preprocess_audio.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 53ccc42c-9498-4a85-ac5a-c1c9c30e5898

📥 Commits

Reviewing files that changed from the base of the PR and between 76d408b and 836052a.

📒 Files selected for processing (1)
  • whispermlx/vads/silero.py

@KalebJS KalebJS self-assigned this Apr 7, 2026
@KalebJS

KalebJS commented Apr 7, 2026

Copy link
Copy Markdown
Owner

LGTM! Tests are coming through fine.

@KalebJS
KalebJS merged commit 9dd4a77 into KalebJS:main Apr 7, 2026
8 checks passed
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