mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-19 00:02:11 +00:00
asynv
This commit is contained in:
+22
-31
@@ -5,7 +5,6 @@ import assemblyai as aai
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import commands, voice_recv, tasks
|
from discord.ext import commands, voice_recv, tasks
|
||||||
from discord.opus import Decoder as OpusDecoder
|
from discord.opus import Decoder as OpusDecoder
|
||||||
from queue import Queue, Empty
|
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
# Replace with your API key
|
# Replace with your API key
|
||||||
@@ -127,11 +126,10 @@ class SRBuffer(voice_recv.AudioSink):
|
|||||||
|
|
||||||
|
|
||||||
class Transcriber(commands.Cog):
|
class Transcriber(commands.Cog):
|
||||||
def __init__(self, bot, worker, queue):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.threads = []
|
self.threads = []
|
||||||
self.comm_queue = queue
|
self.comm_queue = asyncio.Queue()
|
||||||
self.worker = worker
|
|
||||||
self.wsink = SRBuffer(self.comm_queue)
|
self.wsink = SRBuffer(self.comm_queue)
|
||||||
|
|
||||||
@commands.hybrid_command(name="transcribe")
|
@commands.hybrid_command(name="transcribe")
|
||||||
@@ -151,7 +149,7 @@ class Transcriber(commands.Cog):
|
|||||||
logger.info(self.bot.voice_clients)
|
logger.info(self.bot.voice_clients)
|
||||||
self.check_data.start()
|
self.check_data.start()
|
||||||
logger.info("Start worker!~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
logger.info("Start worker!~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||||
self.worker.start()
|
asyncio.run(self.transcribe_output_queue())
|
||||||
vc.listen(self.wsink)
|
vc.listen(self.wsink)
|
||||||
|
|
||||||
|
|
||||||
@@ -196,35 +194,28 @@ class Transcriber(commands.Cog):
|
|||||||
self.comm_queue.put(stop_token)
|
self.comm_queue.put(stop_token)
|
||||||
await ctx.voice_client.disconnect()
|
await ctx.voice_client.disconnect()
|
||||||
|
|
||||||
|
async def transcribe_output_queue(self):
|
||||||
#this needs to be async and transcript fun awaited
|
logger.info("Transcript worker start")
|
||||||
def transcribe_output_queue(queue):
|
config = aai.TranscriptionConfig(speaker_labels=True, language_code="pl")
|
||||||
logger.info("Transcript worker start")
|
transcriber = aai.Transcriber()
|
||||||
config = aai.TranscriptionConfig(speaker_labels=True, language_code="pl")
|
while True:
|
||||||
transcriber = aai.Transcriber()
|
item = self.queue.get()
|
||||||
while True:
|
if item.type == "STOP":
|
||||||
item = queue.get()
|
logger.info("Queue ended")
|
||||||
if item.type == "STOP":
|
break
|
||||||
logger.info("Queue ended")
|
elif item.type == "send_file":
|
||||||
break
|
transcript = ""
|
||||||
elif item.type == "send_file":
|
for iter in item.data:
|
||||||
transcript = ""
|
transcript = transcriber.transcribe(iter, config=config)
|
||||||
for iter in item.data:
|
for utterance in transcript.utterances:
|
||||||
transcript = transcriber.transcribe(iter, config=config)
|
logger.info("%s : %s", item.user, utterance.text)
|
||||||
for utterance in transcript.utterances:
|
elif item.type == "user_cleanup":
|
||||||
logger.info("%s : %s", item.user, utterance.text)
|
logger.info("User %s disconnected - cleanup action")
|
||||||
elif item.type == "user_cleanup":
|
logger.info("End transcript worker")
|
||||||
logger.info("User %s disconnected - cleanup action")
|
|
||||||
logger.info("End transcript worker")
|
|
||||||
|
|
||||||
async def setup(bot):
|
async def setup(bot):
|
||||||
logger = logging.getLogger("discord")
|
logger = logging.getLogger("discord")
|
||||||
logger.info("Loading voice transcribed module phase one")
|
await bot.add_cog(Transcriber(bot))
|
||||||
worker = threading.Thread(target=transcribe_output_queue)
|
|
||||||
logger.info("Loading voice transcribed phasetwo")
|
|
||||||
queue = Queue()
|
|
||||||
logger.info("Loading voice transcribed module phase three")
|
|
||||||
await bot.add_cog(Transcriber(bot, worker, queue))
|
|
||||||
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.
|
||||||
|
|||||||
Reference in New Issue
Block a user