Skip to content

Commit 093669f

Browse files
committed
Enhance Discord voice activity detection configurability
Makes the `silence_threshold` and `min_speech_duration` parameters configurable during `VoiceReceiver` initialization, allowing for dynamic tuning of voice activity detection. The default `min_speech_duration` is also increased from 0.25s to 0.75s to help filter out shorter, potentially spurious speech segments. Additionally, the log level for NaCl decryption failures is reduced from `WARNING` to `DEBUG` to minimize log noise. This commit also updates the project version to 0.6.5.
1 parent ff766d6 commit 093669f

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
__version__ = "0.6.4"
3+
__version__ = "0.6.5"
44
LICENSE = "GNU General Public License v3 or later (GPLv3+)"
55

66

@@ -11,7 +11,7 @@ def get_long_description():
1111

1212
setup(
1313
name="agentforge",
14-
version="0.6.4",
14+
version="0.6.5",
1515
description="AI-driven task automation system",
1616
author="John Smith, Ansel Anselmi",
1717
author_email="contact@agentforge.net",

src/agentforge/utils/discord/discord_voice.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ class VoiceReceiver:
3939
Handles NaCl transport decryption, RTP padding removal, DAVE E2EE decryption,
4040
and Opus decoding natively. (Adapted from Hermes-Agent example.py)
4141
"""
42-
SILENCE_THRESHOLD = 1.5
43-
MIN_SPEECH_DURATION = 0.25
4442
SAMPLE_RATE = 48000
4543
CHANNELS = 2
4644

47-
def __init__(self, voice_client, logger: Logger):
45+
def __init__(self, voice_client, logger: Logger, silence_threshold=1.5, min_speech_duration=0.75):
4846
self._vc = voice_client
4947
self.logger = logger
5048
self._running = False
5149
self._paused = False
5250

51+
# Dynamic attributes for audio filtering
52+
self.silence_threshold = silence_threshold
53+
self.min_speech_duration = min_speech_duration
54+
5355
self._secret_key = None
5456
self._bot_ssrc = 0
5557
self._dave_session = None
@@ -163,7 +165,7 @@ def _on_packet(self, data: bytes):
163165
box = nacl.secret.Aead(self._secret_key)
164166
decrypted = box.decrypt(encrypted, header, bytes(nonce))
165167
except Exception as e:
166-
self.logger.warning(f"NaCl decrypt failed: {e} (hdr={header_size}, enc={len(encrypted)})")
168+
self.logger.debug(f"NaCl decrypt failed: {e} (hdr={header_size}, enc={len(encrypted)})")
167169
return
168170

169171
# Skip encrypted extension data
@@ -226,7 +228,7 @@ def check_silence(self) -> list:
226228
buf = self._buffers[ssrc]
227229
buf_duration = len(buf) / (self.SAMPLE_RATE * self.CHANNELS * 2)
228230

229-
if silence_duration >= self.SILENCE_THRESHOLD and buf_duration >= self.MIN_SPEECH_DURATION:
231+
if silence_duration >= self.silence_threshold and buf_duration >= self.min_speech_duration:
230232
user_id = self._ssrc_to_user.get(ssrc, 0)
231233
if not user_id:
232234
user_id = self._infer_user_for_ssrc(ssrc)
@@ -237,7 +239,7 @@ def check_silence(self) -> list:
237239
self._buffers[ssrc] = bytearray()
238240
self._last_packet_time.pop(ssrc, None)
239241

240-
elif silence_duration >= self.SILENCE_THRESHOLD * 2:
242+
elif silence_duration >= self.silence_threshold * 2:
241243
self._buffers.pop(ssrc, None)
242244
self._last_packet_time.pop(ssrc, None)
243245

0 commit comments

Comments
 (0)