2 コミット fa1f36c4d9 ... ae1ac3463a

作者 SHA1 メッセージ 日付
  Penta ae1ac3463a [3.0.0] Displaying name 3 週間 前
  Penta 3344b8b896 [3.0.0] Refactorisation audio conversion 3 週間 前
1 ファイル変更16 行追加12 行削除
  1. 16 12
      chatbot.py

+ 16 - 12
chatbot.py

@@ -116,7 +116,10 @@ class STTSink(Sink):
                         continue   # ✅ PAS return
 
                     if reply_mode == ReplyMode.TEXT and reply_text_channel:
-                        await reply_text_channel.send(f"🗣️ {text}")
+                        member = reply_text_channel.guild.get_member(user_id)
+                        name = member.display_name if member else f"User {user_id}"
+
+                        await reply_text_channel.send(f"🗣️ **{name}** : {text}")
                     else:
                         logger.info(f"[STT][{user_id}] {text}")
 
@@ -188,21 +191,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)
+
+    # normalisation RMS
+    rms = np.sqrt(np.mean(audio**2) + 1e-8)
+    audio = audio / max(rms, 5000)
 
-    # int16 -> float32 pour resample
-    audio_float32 = audio_48k.astype(np.float32) / 32768.0
+    # passe-bas léger avant downsample
+    audio = audio / 32768.0
 
-    # resample 48kHz -> 16kHz
-    audio_16k = resample_poly(audio_float32, up=1, down=3)
+    # resample 48k → 16k
+    audio_16k = resample_poly(audio, up=1, down=3, window=('kaiser', 5.0))
 
-    # float32 -> int16 (CE QUE WHISPER ATTEND)
-    audio_16k_int16 = np.clip(audio_16k * 32768.0, -32768, 32767).astype(np.int16)
+    # clip sécurité
+    audio_16k = np.clip(audio_16k, -1.0, 1.0)
 
-    return audio_16k_int16.tobytes()
+    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"""