|
|
@@ -188,21 +188,22 @@ class STTSink(Sink):
|
|
|
conversation_history = []
|
|
|
|
|
|
def discord_pcm_to_whisper_int16(pcm_bytes: bytes) -> bytes:
|
|
|
- # PCM 48 kHz int16 -> numpy
|
|
|
- audio_48k = np.frombuffer(pcm_bytes, dtype=np.int16)
|
|
|
- if audio_48k.size == 0:
|
|
|
- return b""
|
|
|
+ audio = np.frombuffer(pcm_bytes, dtype=np.int16).astype(np.float32)
|
|
|
|
|
|
- # int16 -> float32 pour resample
|
|
|
- audio_float32 = audio_48k.astype(np.float32) / 32768.0
|
|
|
+ # normalisation RMS
|
|
|
+ rms = np.sqrt(np.mean(audio**2) + 1e-8)
|
|
|
+ audio = audio / max(rms, 5000)
|
|
|
|
|
|
- # resample 48kHz -> 16kHz
|
|
|
- audio_16k = resample_poly(audio_float32, up=1, down=3)
|
|
|
+ # passe-bas léger avant downsample
|
|
|
+ audio = audio / 32768.0
|
|
|
|
|
|
- # float32 -> int16 (CE QUE WHISPER ATTEND)
|
|
|
- audio_16k_int16 = np.clip(audio_16k * 32768.0, -32768, 32767).astype(np.int16)
|
|
|
+ # resample 48k → 16k
|
|
|
+ audio_16k = resample_poly(audio, up=1, down=3, window=('kaiser', 5.0))
|
|
|
|
|
|
- return audio_16k_int16.tobytes()
|
|
|
+ # clip sécurité
|
|
|
+ audio_16k = np.clip(audio_16k, -1.0, 1.0)
|
|
|
+
|
|
|
+ return (audio_16k * 32767).astype(np.int16).tobytes()
|
|
|
|
|
|
def filter_message(message):
|
|
|
"""Filtre le contenu d'un retour de modèle de language, comme pour enlever les pensées dans le cas par exemple de DeepSeek"""
|