diff --git a/main.py b/main.py index 2059f53..6f829e4 100644 --- a/main.py +++ b/main.py @@ -34,7 +34,6 @@ def mqtt_on_message(client, userdata, msg): def mqtt_handle_message(filename): - # Transcribe audio if the talkgroup is one we're interested in talkgroup = int(filename.split("-")[0]) if check_tg(talkgroup): @@ -52,8 +51,15 @@ def mqtt_handle_message(filename): # fire off discord notification unless there's no transcription text if fulltext: - asyncio.run(send_discord_webhook(talkgroup, filename, fulltext)) - logging.info(f"Transcription of {filename}: {fulltext}") + try: + # Set up a new event loop for this thread + new_loop = asyncio.new_event_loop() + asyncio.set_event_loop(new_loop) + new_loop.run_until_complete(send_discord_webhook(talkgroup, filename, fulltext)) + new_loop.close() + logging.info(f"Transcription of {filename}: {fulltext}") + except Exception as e: + logging.error(f"Failed to send Discord webhook: {e}") if not fulltext: logging.info(f"Transcription of {filename}: No text found.")