Skip to content

Commit

Permalink
Use chunk_samples in SileroVad to avoid InvalidChunkSizeError
Browse files Browse the repository at this point in the history
  • Loading branch information
colonelpanic8 committed Feb 6, 2025
1 parent f86d236 commit 078a0cd
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions wyoming_satellite/vad.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Voice activity detection."""
from typing import Optional
from .utils import AudioBuffer, chunk_samples


class SileroVad:
Expand All @@ -12,6 +13,7 @@ def __init__(self, threshold: float, trigger_level: int) -> None:
self.threshold = threshold
self.trigger_level = trigger_level
self._activation = 0
self._audio_buffer = AudioBuffer(self.detector.chunk_bytes())

def __call__(self, audio_bytes: Optional[bytes]) -> bool:
if audio_bytes is None:
Expand All @@ -20,12 +22,17 @@ def __call__(self, audio_bytes: Optional[bytes]) -> bool:
self.detector.reset()
return False

if self.detector(audio_bytes) >= self.threshold:
# Speech detected
self._activation += 1
if self._activation >= self.trigger_level:
self._activation = 0
return True
for sub_chunk in chunk_samples(
audio_bytes,
self.detector.chunk_bytes(),
self._audio_buffer
):
if self.detector(audio_bytes) >= self.threshold:
# Speech detected
self._activation += 1
if self._activation >= self.trigger_level:
self._activation = 0
return True
else:
# Silence detected
self._activation = max(0, self._activation - 1)
Expand Down

0 comments on commit 078a0cd

Please sign in to comment.