|
@@ -16,7 +16,7 @@ from io import BytesIO
|
|
|
from datetime import datetime, timezone, timedelta
|
|
from datetime import datetime, timezone, timedelta
|
|
|
from charset_normalizer import from_bytes
|
|
from charset_normalizer import from_bytes
|
|
|
from enum import Enum
|
|
from enum import Enum
|
|
|
-from discord.sinks import Sink
|
|
|
|
|
|
|
+from discord.sinks import RawData
|
|
|
from scipy.signal import resample_poly
|
|
from scipy.signal import resample_poly
|
|
|
|
|
|
|
|
|
|
|
|
@@ -89,7 +89,7 @@ class ReplyMode(Enum):
|
|
|
reply_mode = ReplyMode.VOICE
|
|
reply_mode = ReplyMode.VOICE
|
|
|
reply_text_channel = None
|
|
reply_text_channel = None
|
|
|
|
|
|
|
|
-class STTSink(Sink):
|
|
|
|
|
|
|
+class STTSink(RawData):
|
|
|
def __init__(self):
|
|
def __init__(self):
|
|
|
super().__init__()
|
|
super().__init__()
|
|
|
self.user_ws = {}
|
|
self.user_ws = {}
|
|
@@ -115,25 +115,21 @@ class STTSink(Sink):
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
logger.warning(f"[STT][{user_id}] WS fermé : {e}")
|
|
logger.warning(f"[STT][{user_id}] WS fermé : {e}")
|
|
|
|
|
|
|
|
- def write(self, data):
|
|
|
|
|
- if not data or not hasattr(data, "pcm"):
|
|
|
|
|
|
|
+ # ⚠️ SIGNATURE OBLIGATOIRE
|
|
|
|
|
+ def write(self, pcm_bytes: bytes, user_id: int):
|
|
|
|
|
+ if not pcm_bytes:
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
- user = data.user
|
|
|
|
|
-
|
|
|
|
|
- if not user:
|
|
|
|
|
- return
|
|
|
|
|
-
|
|
|
|
|
- audio_16k_float32 = discord_pcm_to_whisper_float32(data.pcm)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ audio_16k_float32 = discord_pcm_to_whisper_float32(pcm_bytes)
|
|
|
if not audio_16k_float32:
|
|
if not audio_16k_float32:
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
- asyncio.create_task(
|
|
|
|
|
- self._send_audio(user.id, audio_16k_float32)
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ asyncio.create_task(self._send_audio(user_id, audio_16k_float32))
|
|
|
|
|
|
|
|
- logger.debug(f"[STT] audio envoyé user={user.id} bytes={len(audio_16k_float32)}")
|
|
|
|
|
|
|
+ logger.debug(
|
|
|
|
|
+ f"[STT] audio reçu user={user_id} "
|
|
|
|
|
+ f"bytes_in={len(pcm_bytes)} bytes_out={len(audio_16k_float32)}"
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
async def _send_audio(self, user_id, pcm_bytes):
|
|
async def _send_audio(self, user_id, pcm_bytes):
|
|
|
ws = await self._get_ws(user_id)
|
|
ws = await self._get_ws(user_id)
|