Эх сурвалжийг харах

[3.0.0] threading issue fixed

Penta 3 долоо хоног өмнө
parent
commit
28278e6261
1 өөрчлөгдсөн 4 нэмэгдсэн , 2 устгасан
  1. 4 2
      chatbot.py

+ 4 - 2
chatbot.py

@@ -115,16 +115,16 @@ class STTSink(Sink):
         except Exception as e:
             logger.warning(f"[STT][{user_id}] WS fermé : {e}")
 
-    # ⚠️ SIGNATURE OBLIGATOIRE
     def write(self, pcm_bytes: bytes, user_id: int):
         if not pcm_bytes:
             return
 
         audio_16k_float32 = discord_pcm_to_whisper_float32(pcm_bytes)
+
         if not audio_16k_float32:
             return
 
-        asyncio.create_task(self._send_audio(user_id, audio_16k_float32))
+        asyncio.run_coroutine_threadsafe(self._send_audio(user_id, audio_16k_float32), MAIN_LOOP)
 
         logger.debug(
             f"[STT] audio reçu user={user_id} "
@@ -309,6 +309,8 @@ except ValueError:
 # Initialiser le client Discord avec les intents modifiés
 client_discord = discord.Bot(intents=intents)
 
+MAIN_LOOP = asyncio.get_event_loop()
+
 # Appeler la fonction pour charger l'historique au démarrage
 load_conversation_history()