Merge pull request #340 from pipecat-ai/lewis/silero-vad-via-pip
Install Silero VAD via pip
This commit is contained in:
@@ -9,8 +9,5 @@ COPY *.py .
|
|||||||
COPY ./requirements.txt requirements.txt
|
COPY ./requirements.txt requirements.txt
|
||||||
RUN pip3 install --no-cache-dir --upgrade -r requirements.txt
|
RUN pip3 install --no-cache-dir --upgrade -r requirements.txt
|
||||||
|
|
||||||
# Install models
|
|
||||||
RUN python3 install_deps.py
|
|
||||||
|
|
||||||
# Start the FastAPI server
|
# Start the FastAPI server
|
||||||
CMD python3 bot_runner.py --port ${FAST_API_PORT}
|
CMD python3 bot_runner.py --port ${FAST_API_PORT}
|
||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
This project modifies the `bot_runner.py` server to launch a new machine for each user session. This is a recommended approach for production vs. running shell processess as your deployment will quickly run out of system resources under load.
|
This project modifies the `bot_runner.py` server to launch a new machine for each user session. This is a recommended approach for production vs. running shell processess as your deployment will quickly run out of system resources under load.
|
||||||
|
|
||||||
To speed up machine boot times, we also download and cache Silero VAD as part of the Dockerfile (`install_deps.py`). If you are using other custom models, you can add them here too.
|
|
||||||
|
|
||||||
For this example, we are using Daily as a WebRTC transport and provisioning a new room and token for each session. You can use another transport, such as WebSockets, by modifying the `bot.py` and `bot_runner.py` files accordingly.
|
For this example, we are using Daily as a WebRTC transport and provisioning a new room and token for each session. You can use another transport, such as WebSockets, by modifying the `bot.py` and `bot_runner.py` files accordingly.
|
||||||
|
|
||||||
## Setting up your fly.io deployment
|
## Setting up your fly.io deployment
|
||||||
@@ -32,7 +30,6 @@ Note: you can do this manually via the fly.io dashboard under the "secrets" sub-
|
|||||||
|
|
||||||
`fly deploy`
|
`fly deploy`
|
||||||
|
|
||||||
|
|
||||||
## Connecting to your bot
|
## Connecting to your bot
|
||||||
|
|
||||||
Send a post request to your running fly.io instance:
|
Send a post request to your running fly.io instance:
|
||||||
@@ -40,4 +37,3 @@ Send a post request to your running fly.io instance:
|
|||||||
`curl --location --request POST 'https://YOUR_FLY_APP_NAME/start_bot'`
|
`curl --location --request POST 'https://YOUR_FLY_APP_NAME/start_bot'`
|
||||||
|
|
||||||
This request will wait until the machine enters into a `starting` state, before returning the a room URL and token to join.
|
This request will wait until the machine enters into a `starting` state, before returning the a room URL and token to join.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
import torch
|
|
||||||
|
|
||||||
# Download (cache) the Silero VAD model
|
|
||||||
torch.hub.load(repo_or_dir='snakers4/silero-vad', model='silero_vad', force_reload=True)
|
|
||||||
@@ -50,7 +50,7 @@ moondream = [ "einops~=0.8.0", "timm~=0.9.16", "transformers~=4.40.2" ]
|
|||||||
openai = [ "openai~=1.35.0" ]
|
openai = [ "openai~=1.35.0" ]
|
||||||
openpipe = [ "openpipe~=4.18.0" ]
|
openpipe = [ "openpipe~=4.18.0" ]
|
||||||
playht = [ "pyht~=0.0.28" ]
|
playht = [ "pyht~=0.0.28" ]
|
||||||
silero = [ "torch~=2.3.1", "torchaudio~=2.3.1" ]
|
silero = [ "silero-vad~=5.1" ]
|
||||||
websocket = [ "websockets~=12.0", "fastapi~=0.111.0" ]
|
websocket = [ "websockets~=12.0", "fastapi~=0.111.0" ]
|
||||||
whisper = [ "faster-whisper~=1.0.3" ]
|
whisper = [ "faster-whisper~=1.0.3" ]
|
||||||
xtts = [ "resampy~=0.4.3" ]
|
xtts = [ "resampy~=0.4.3" ]
|
||||||
|
|||||||
@@ -15,12 +15,8 @@ from pipecat.vad.vad_analyzer import VADAnalyzer, VADParams, VADState
|
|||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
from silero_vad import load_silero_vad
|
||||||
import torch
|
import torch
|
||||||
# We don't use torchaudio here, but we need to try importing it because
|
|
||||||
# Silero uses it.
|
|
||||||
import torchaudio
|
|
||||||
|
|
||||||
torch.set_num_threads(1)
|
|
||||||
|
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
logger.error(f"Exception: {e}")
|
logger.error(f"Exception: {e}")
|
||||||
@@ -37,10 +33,6 @@ class SileroVADAnalyzer(VADAnalyzer):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
sample_rate: int = 16000,
|
sample_rate: int = 16000,
|
||||||
version: str = "v5.0",
|
|
||||||
force_reload: bool = False,
|
|
||||||
skip_validation: bool = True,
|
|
||||||
trust_repo: bool = True,
|
|
||||||
params: VADParams = VADParams()):
|
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)
|
||||||
|
|
||||||
@@ -49,11 +41,7 @@ class SileroVADAnalyzer(VADAnalyzer):
|
|||||||
|
|
||||||
logger.debug("Loading Silero VAD model...")
|
logger.debug("Loading Silero VAD model...")
|
||||||
|
|
||||||
(self._model, _) = torch.hub.load(repo_or_dir=f"snakers4/silero-vad:{version}",
|
self._model = load_silero_vad()
|
||||||
model="silero_vad",
|
|
||||||
force_reload=force_reload,
|
|
||||||
skip_validation=skip_validation,
|
|
||||||
trust_repo=trust_repo)
|
|
||||||
|
|
||||||
self._last_reset_time = 0
|
self._last_reset_time = 0
|
||||||
|
|
||||||
@@ -94,20 +82,12 @@ class SileroVAD(FrameProcessor):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
sample_rate: int = 16000,
|
sample_rate: int = 16000,
|
||||||
version: str = "v5.0",
|
|
||||||
force_reload: bool = False,
|
|
||||||
skip_validation: bool = True,
|
|
||||||
trust_repo: bool = True,
|
|
||||||
vad_params: VADParams = VADParams(),
|
vad_params: VADParams = VADParams(),
|
||||||
audio_passthrough: bool = False):
|
audio_passthrough: bool = False):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self._vad_analyzer = SileroVADAnalyzer(
|
self._vad_analyzer = SileroVADAnalyzer(
|
||||||
sample_rate=sample_rate,
|
sample_rate=sample_rate,
|
||||||
version=version,
|
|
||||||
force_reload=force_reload,
|
|
||||||
skip_validation=skip_validation,
|
|
||||||
trust_repo=trust_repo,
|
|
||||||
params=vad_params)
|
params=vad_params)
|
||||||
self._audio_passthrough = audio_passthrough
|
self._audio_passthrough = audio_passthrough
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user