This commit is contained in:
2024-09-20 14:19:16 +02:00
parent b3121aaaf2
commit b025790b3d
+10 -14
View File
@@ -126,10 +126,11 @@ class SRBuffer(voice_recv.AudioSink):
class Transcriber(commands.Cog): class Transcriber(commands.Cog):
def __init__(self, bot): def __init__(self, bot, worker, queue):
self.bot = bot self.bot = bot
self.threads = [] self.threads = []
self.comm_queue = Queue() self.comm_queue = queue
self.worker = worker
self.wsink = SRBuffer(self.comm_queue) self.wsink = SRBuffer(self.comm_queue)
async def transcribe(self,file_url): async def transcribe(self,file_url):
config = aai.TranscriptionConfig(speaker_labels=True, language_code="pl") config = aai.TranscriptionConfig(speaker_labels=True, language_code="pl")
@@ -156,7 +157,7 @@ class Transcriber(commands.Cog):
logger.info(self.bot.voice_clients) logger.info(self.bot.voice_clients)
self.output_handler.work = True self.output_handler.work = True
self.output_handler.scan_loop.start() self.output_handler.scan_loop.start()
self.worker.start()
vc.listen(self.wsink) vc.listen(self.wsink)
@tasks.loop(seconds=0.5) @tasks.loop(seconds=0.5)
@@ -208,27 +209,22 @@ class Transcriber(commands.Cog):
self.output_handler.work = False self.output_handler.work = False
self.check_data.stop() self.check_data.stop()
self.worker.stop()
await ctx.voice_client.disconnect() await ctx.voice_client.disconnect()
def transcribe_output_queue(): def transcribe_output_queue(queue):
while True: while True:
time.sleep(10.0) queue.get()
logger.info("PING") logger.info("PING")
async def setup(bot): async def setup(bot):
logger = logging.getLogger("discord") logger = logging.getLogger("discord")
logger.info("Loading voice transcribed module phase one") logger.info("Loading voice transcribed module phase one")
threads = [] worker = threading.Thread(target=transcribe_output_queue)
threads.append(threading.Thread(target=transcribe_output_queue))
logger.info("Loading voice transcribed phase two") logger.info("Loading voice transcribed phase two")
queue = Queue()
for worker in threads:
worker.start()
logger.info("Loading voice transcribed module phase three") logger.info("Loading voice transcribed module phase three")
await bot.add_cog(Transcriber(bot, worker, queue))
await bot.add_cog(Transcriber(bot))
logger.info("Loading voice transcribed module done") logger.info("Loading voice transcribed module done")
# 1. zapisuj kwestie człowieka do pliku w którym będzie można stwierdzić kto co powiedział (callback z basicaudio + write z wavesinka). Zamykaj plik i wysyłaj do transkrypcji w momencie ciszy dłuższej niż 0.5s. Jeśli człowiek nadaje cały czas dawaj sygnał że nie można go transkrybować - i wyłaczaj zapis. # 1. zapisuj kwestie człowieka do pliku w którym będzie można stwierdzić kto co powiedział (callback z basicaudio + write z wavesinka). Zamykaj plik i wysyłaj do transkrypcji w momencie ciszy dłuższej niż 0.5s. Jeśli człowiek nadaje cały czas dawaj sygnał że nie można go transkrybować - i wyłaczaj zapis.