|
|
@@ -96,6 +96,24 @@ class STTSink(Sink):
|
|
|
self.user_ws = {}
|
|
|
self.buffers = {} # audio accumulé par user
|
|
|
self.last_send = {} # timestamp dernier envoi
|
|
|
+ self.last_voice = {}
|
|
|
+
|
|
|
+ asyncio.run_coroutine_threadsafe(self._send_silence_loop(), MAIN_LOOP)
|
|
|
+
|
|
|
+ async def _send_silence_loop(self):
|
|
|
+ while True:
|
|
|
+ await asyncio.sleep(0.2)
|
|
|
+ now = time.time()
|
|
|
+
|
|
|
+ for user_id, last in list(self.last_voice.items()):
|
|
|
+ if now - last > 0.7:
|
|
|
+ # 200 ms de silence @ 16kHz int16
|
|
|
+ silence = np.zeros(3200, dtype=np.int16).tobytes()
|
|
|
+
|
|
|
+ await self._send_audio(user_id, silence)
|
|
|
+
|
|
|
+ # reset pour éviter le spam
|
|
|
+ self.last_voice[user_id] = now
|
|
|
|
|
|
async def _get_ws(self, user_id):
|
|
|
if user_id not in self.user_ws:
|
|
|
@@ -123,9 +141,12 @@ class STTSink(Sink):
|
|
|
return
|
|
|
|
|
|
audio = discord_pcm_to_whisper_int16(pcm_bytes)
|
|
|
+
|
|
|
if not audio:
|
|
|
return
|
|
|
|
|
|
+ self.last_voice[user_id] = time.time()
|
|
|
+
|
|
|
if user_id not in self.buffers:
|
|
|
self.buffers[user_id] = []
|
|
|
self.last_send[user_id] = time.time()
|