Repository navigation
fix: normalize Silero waveforms before device transfer - #3
Conversation
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.
📝 WalkthroughWalkthroughThe Silero VAD module is updated to consistently convert audio waveforms to PyTorch Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
whispermlx/vads/silero.py (1)
44-47: Consolidate normalization in__call__viapreprocess_audio.Line 45-47 only normalizes non-tensor inputs, while
preprocess_audionow 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.
|
LGTM! Tests are coming through fine. |
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