Skip to content

Commit

Permalink
Merge pull request #266 from pipecat-ai/aleix/silero-num-frames-fixes
Browse files Browse the repository at this point in the history
vad: fix Silero VAD required number of frames
  • Loading branch information
aconchillo authored Jun 28, 2024
2 parents 8691d14 + cce1ddb commit 8dff460
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ All notable changes to **pipecat** will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.35] - 2024-06-28

### Changed

- `FastAPIWebsocketParams` now require a serializer.

- `TwilioFrameSerializer` now requires a `streamSid`.

### Fixed

- Silero VAD number of frames needs to be 512 for 16000 sample rate or 256 for
8000 sample rate.

## [0.0.34] - 2024-06-25

### Fixed
Expand Down
5 changes: 4 additions & 1 deletion src/pipecat/vad/silero.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class SileroVADAnalyzer(VADAnalyzer):
def __init__(self, sample_rate=16000, params: VADParams = VADParams()):
super().__init__(sample_rate=sample_rate, num_channels=1, params=params)

if sample_rate != 16000 and sample_rate != 8000:
raise Exception("Silero VAD sample rate needs to be 16000 or 8000")

logger.debug("Loading Silero VAD model...")

(self._model, utils) = torch.hub.load(
Expand All @@ -51,7 +54,7 @@ def __init__(self, sample_rate=16000, params: VADParams = VADParams()):
#

def num_frames_required(self) -> int:
return int(self.sample_rate / 100) * 4 # 40ms
return 512 if self.sample_rate == 16000 else 256

def voice_confidence(self, buffer) -> float:
try:
Expand Down

0 comments on commit 8dff460

Please sign in to comment.