refactor: remove constants and put in config file
removed all constants from all files and put them in src/control_backend/core/config.py also removed some old mock agents that we don't use anymore ref: N25B-236
This commit is contained in:
@@ -20,7 +20,11 @@ class SocketPoller[T]:
|
||||
multiple usages.
|
||||
"""
|
||||
|
||||
def __init__(self, socket: azmq.Socket, timeout_ms: int = 100):
|
||||
def __init__(
|
||||
self,
|
||||
socket: azmq.Socket,
|
||||
timeout_ms: int = settings.behaviour_settings.socket_poller_timeout_ms,
|
||||
):
|
||||
"""
|
||||
:param socket: The socket to poll and get data from.
|
||||
:param timeout_ms: A timeout in milliseconds to wait for data.
|
||||
@@ -49,12 +53,16 @@ class Streaming(CyclicBehaviour):
|
||||
super().__init__()
|
||||
self.audio_in_poller = SocketPoller[bytes](audio_in_socket)
|
||||
self.model, _ = torch.hub.load(
|
||||
repo_or_dir="snakers4/silero-vad", model="silero_vad", force_reload=False
|
||||
repo_or_dir=settings.vad_settings.repo_or_dir,
|
||||
model=settings.vad_settings.model_name,
|
||||
force_reload=False,
|
||||
)
|
||||
self.audio_out_socket = audio_out_socket
|
||||
|
||||
self.audio_buffer = np.array([], dtype=np.float32)
|
||||
self.i_since_speech = 100 # Used to allow small pauses in speech
|
||||
self.i_since_speech = (
|
||||
settings.behaviour_settings.vad_initial_since_speech
|
||||
) # Used to allow small pauses in speech
|
||||
|
||||
async def run(self) -> None:
|
||||
data = await self.audio_in_poller.poll()
|
||||
@@ -62,15 +70,17 @@ class Streaming(CyclicBehaviour):
|
||||
if len(self.audio_buffer) > 0:
|
||||
logger.debug("No audio data received. Discarding buffer until new data arrives.")
|
||||
self.audio_buffer = np.array([], dtype=np.float32)
|
||||
self.i_since_speech = 100
|
||||
self.i_since_speech = settings.behaviour_settings.vad_initial_since_speech
|
||||
return
|
||||
|
||||
# copy otherwise Torch will be sad that it's immutable
|
||||
chunk = np.frombuffer(data, dtype=np.float32).copy()
|
||||
prob = self.model(torch.from_numpy(chunk), 16000).item()
|
||||
prob = self.model(torch.from_numpy(chunk), settings.vad_settings.sample_rate_hz).item()
|
||||
non_speech_patience = settings.behaviour_settings.vad_non_speech_patience_chunks
|
||||
prob_threshold = settings.behaviour_settings.vad_prob_threshold
|
||||
|
||||
if prob > 0.5:
|
||||
if self.i_since_speech > 3:
|
||||
if prob > prob_threshold:
|
||||
if self.i_since_speech > non_speech_patience:
|
||||
logger.debug("Speech started.")
|
||||
self.audio_buffer = np.append(self.audio_buffer, chunk)
|
||||
self.i_since_speech = 0
|
||||
@@ -78,7 +88,7 @@ class Streaming(CyclicBehaviour):
|
||||
self.i_since_speech += 1
|
||||
|
||||
# prob < 0.5, so speech maybe ended. Wait a bit more before to be more certain
|
||||
if self.i_since_speech <= 3:
|
||||
if self.i_since_speech <= non_speech_patience:
|
||||
self.audio_buffer = np.append(self.audio_buffer, chunk)
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user