From 836052a47169cb19be4b94ee41cf066c755e5e3d Mon Sep 17 00:00:00 2001 From: wey Date: Tue, 7 Apr 2026 11:26:44 +0800 Subject: [PATCH] fix: normalize Silero waveforms before device transfer 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. --- whispermlx/vads/silero.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/whispermlx/vads/silero.py b/whispermlx/vads/silero.py index ec37daf7f..3850b3c6c 100644 --- a/whispermlx/vads/silero.py +++ b/whispermlx/vads/silero.py @@ -41,8 +41,12 @@ def __call__(self, audio: AudioFile, **kwargs): if sample_rate != 16000: raise ValueError("Only 16000Hz sample rate is allowed") + waveform = audio["waveform"] + if not torch.is_tensor(waveform): + waveform = torch.as_tensor(waveform, dtype=torch.float32) + timestamps = self.get_speech_timestamps( - audio["waveform"].to(self.device), + waveform.to(self.device), model=self.vad_pipeline, sampling_rate=sample_rate, max_speech_duration_s=self.chunk_size, @@ -59,7 +63,9 @@ def __call__(self, audio: AudioFile, **kwargs): @staticmethod def preprocess_audio(audio): - return audio + if torch.is_tensor(audio): + return audio.to(dtype=torch.float32) + return torch.as_tensor(audio, dtype=torch.float32) @staticmethod def merge_chunks(