From 554852bc53c7062cd6499d6eef32f7e2a318862c Mon Sep 17 00:00:00 2001 From: mtuszowski Date: Thu, 19 Sep 2024 12:40:30 +0200 Subject: [PATCH] 11 --- voice_recognition.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/voice_recognition.py b/voice_recognition.py index 3724036..edd7b6e 100644 --- a/voice_recognition.py +++ b/voice_recognition.py @@ -5,6 +5,7 @@ import assemblyai as aai import discord from discord.ext import commands, voice_recv from discord.opus import Decoder as OpusDecoder +from queue import Queue, Empty # Replace with your API key aai.settings.api_key = "aa9962f0088a449a9c4ab2361e96cc08" @@ -126,6 +127,8 @@ class Transcriber(commands.Cog): self.bot = bot self._last_member = None self.wsink = SRBuffer(destination="/home/pi/Conjurer/wav.wav") + self.threads = [] + self.comm_queue = Queue() async def transcribe(file_url): config = aai.TranscriptionConfig(speaker_labels=True, language_code="pl") @@ -138,7 +141,11 @@ class Transcriber(commands.Cog): @commands.hybrid_command(name="transcribe") async def test(self, ctx): logger.info("Attempt transcribe") - vc = await ctx.author.voice.channel.connect(cls=voice_recv.VoiceRecvClient) + if ctx.client.voice_clients: + voice_client = ctx.client.voice_clients[0] + if not voice_client.is_connected(): + logger.info("Connecting to voice") + vc = await ctx.author.voice.channel.connect(cls=voice_recv.VoiceRecvClient) logger.info("Connected") vc.listen(self.wsink)