Просмотр исходного кода

fix: restore _send method, move _drain_queue before __main__

wenhongquan 3 недель назад
Родитель
Сommit
4b1a2ae8db
1 измененных файлов с 11 добавлено и 3 удалено
  1. 11 3
      asr_agent/conversation_worker.py

+ 11 - 3
asr_agent/conversation_worker.py

@@ -666,6 +666,13 @@ class Worker:
         except Exception:
             logger.exception("TTS failed")
 
+    async def _send(self, msg: dict):
+        try:
+            await self.room.local_participant.publish_data(
+                json.dumps(msg, ensure_ascii=False).encode(),
+                reliable=True, topic="transcription",
+            )
+        except Exception:
             pass
 
 
@@ -678,9 +685,6 @@ async def main():
     await Worker(a.room).run()
 
 
-if __name__ == "__main__":
-    asyncio.run(main())
-
 def _drain_queue(q: "asyncio.Queue") -> None:
     """Discard any queued-but-not-yet-played TTS audio."""
     while not q.empty():
@@ -689,3 +693,7 @@ def _drain_queue(q: "asyncio.Queue") -> None:
         except Exception:
             break
 
+
+if __name__ == "__main__":
+    asyncio.run(main())
+