vad(silero): allow specifying a Silero VAD version

This commit is contained in:
Aleix Conchillo Flaqué
2024-06-29 10:36:48 -07:00
parent 1b45946a61
commit efbe7297f7
2 changed files with 15 additions and 5 deletions

View File

@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- It is now possible to specify a Silero VAD version when using `SileroVADAnalyzer`
or `SileroVAD`.
- Added `AysncFrameProcessor` and `AsyncAIService`. Some services like - Added `AysncFrameProcessor` and `AsyncAIService`. Some services like
`DeepgramSTTService` need to process things asynchronously. For example, audio `DeepgramSTTService` need to process things asynchronously. For example, audio
is sent to Deepgram but transcriptions are not returned immediately. In these is sent to Deepgram but transcriptions are not returned immediately. In these

View File

@@ -33,7 +33,11 @@ _MODEL_RESET_STATES_TIME = 5.0
class SileroVADAnalyzer(VADAnalyzer): class SileroVADAnalyzer(VADAnalyzer):
def __init__(self, sample_rate=16000, params: VADParams = VADParams()): def __init__(
self,
sample_rate: int = 16000,
version: str = "v5.0",
params: VADParams = VADParams()):
super().__init__(sample_rate=sample_rate, num_channels=1, params=params) super().__init__(sample_rate=sample_rate, num_channels=1, params=params)
if sample_rate != 16000 and sample_rate != 8000: if sample_rate != 16000 and sample_rate != 8000:
@@ -41,9 +45,10 @@ class SileroVADAnalyzer(VADAnalyzer):
logger.debug("Loading Silero VAD model...") logger.debug("Loading Silero VAD model...")
(self._model, utils) = torch.hub.load( (self._model, _) = torch.hub.load(repo_or_dir=f"snakers4/silero-vad:{version}",
repo_or_dir="snakers4/silero-vad", model="silero_vad", force_reload=False model="silero_vad",
) force_reload=False,
trust_repo=True)
self._last_reset_time = 0 self._last_reset_time = 0
@@ -83,11 +88,13 @@ class SileroVAD(FrameProcessor):
def __init__( def __init__(
self, self,
sample_rate: int = 16000, sample_rate: int = 16000,
version: str = "v5.0",
vad_params: VADParams = VADParams(), vad_params: VADParams = VADParams(),
audio_passthrough: bool = False): audio_passthrough: bool = False):
super().__init__() super().__init__()
self._vad_analyzer = SileroVADAnalyzer(sample_rate=sample_rate, params=vad_params) self._vad_analyzer = SileroVADAnalyzer(
sample_rate=sample_rate, version=version, params=vad_params)
self._audio_passthrough = audio_passthrough self._audio_passthrough = audio_passthrough
self._processor_vad_state: VADState = VADState.QUIET self._processor_vad_state: VADState = VADState.QUIET