mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
Fixing debug levels
This commit is contained in:
+17
-31
@@ -30,11 +30,9 @@ class CommunicationObject:
|
||||
class WaveWriter:
|
||||
def __init__(self, user_id, queue):
|
||||
self.queue = queue
|
||||
logger.info("Wavewriter queue id: %s",id(self.queue))
|
||||
self.user = user_id
|
||||
self.username = str(user_id.id)
|
||||
logger.info("Creating Wavewriter %s", self.username)
|
||||
logger.info(user_id)
|
||||
#here we can add hashing function to make transcription files not possible to be connected with discord id
|
||||
self.present_file_id = 0
|
||||
self.file_name_past = None
|
||||
self.file_name_present = location + self.username + "_" + str(self.present_file_id) + ".mp3"
|
||||
@@ -70,7 +68,6 @@ class WaveWriter:
|
||||
self.transcript_file_future.setsampwidth(SAMPLE_WIDTH)
|
||||
self.transcript_file_future.setframerate(SAMPLING_RATE)
|
||||
operation = CommunicationObject(msg_type="send_file",user=self.user,data=[self.file_name_past])
|
||||
logger.info("Item added to queue %s %s", self.queue, operation)
|
||||
|
||||
await self.queue.put(operation)
|
||||
|
||||
@@ -134,7 +131,6 @@ class Transcriber(commands.Cog):
|
||||
|
||||
@commands.hybrid_command(name="transcribe")
|
||||
async def test(self, ctx):
|
||||
logger.info("Attempt transcribe")
|
||||
if self.vc:
|
||||
vc = self.vc #to juz powinien byc voice channel z funkcja conenct
|
||||
else:
|
||||
@@ -142,16 +138,14 @@ class Transcriber(commands.Cog):
|
||||
self.mc = ctx.message.channel
|
||||
if self.bot.voice_clients:
|
||||
if isinstance(self.bot.voice_clients[0], voice_recv.VoiceRecvClient):
|
||||
logger.info("Already transcribing")
|
||||
logger.debug("Already transcribing")
|
||||
else:
|
||||
logger.info("Already connected with other client")
|
||||
logger.info(self.bot.voice_clients)
|
||||
logger.debug("Already connected with other client")
|
||||
else:
|
||||
logger.info("Connected")
|
||||
logger.debug("Connected")
|
||||
vc = await ctx.author.voice.channel.connect(cls=voice_recv.VoiceRecvClient)
|
||||
logger.info(self.bot.voice_clients)
|
||||
self.check_data.start()
|
||||
logger.info("Start worker!~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||
self.worker = asyncio.create_task(self.transcribe_output_queue())
|
||||
vc.listen(self.wsink)
|
||||
|
||||
@@ -159,13 +153,12 @@ class Transcriber(commands.Cog):
|
||||
@tasks.loop(seconds=0.5)
|
||||
async def check_data(self):
|
||||
for item in self.wsink.wavewriter.values():
|
||||
logger.info("Item %s", item)
|
||||
if not item[3]:
|
||||
timediff_rotation = time.time_ns() - item[2]
|
||||
timediff_write = time.time_ns() -item[1]
|
||||
if timediff_rotation > 3000149433 and timediff_write > 500014943 and item[4]:
|
||||
logger.info("File rotation time since last write %s", timediff_write/1e9)
|
||||
logger.info("File rotation time since last rotation %s", timediff_rotation/1e9)
|
||||
logger.debug("File rotation time since last write %s", timediff_write/1e9)
|
||||
logger.debug("File rotation time since last rotation %s", timediff_rotation/1e9)
|
||||
item[2] = time.time_ns()
|
||||
item[4] = False
|
||||
await item[0].rotate()
|
||||
@@ -174,7 +167,7 @@ class Transcriber(commands.Cog):
|
||||
@commands.Cog.listener()
|
||||
async def on_voice_state_update(self, user, before, after):
|
||||
if user == self.bot.user:
|
||||
logger.info("Ignoring self")
|
||||
logger.debug("Ignoring self")
|
||||
return
|
||||
|
||||
if before.channel is None:
|
||||
@@ -183,41 +176,38 @@ class Transcriber(commands.Cog):
|
||||
elif after.channel is None:
|
||||
logger.info("User %s disconnected from channel %s", user, before.channel.name)
|
||||
operation = CommunicationObject(msg_type="user_cleanup", user=user, data=None)
|
||||
logger.info("Item added to queue %s %s", self.comm_queue, operation)
|
||||
await self.comm_queue.put(operation)
|
||||
else:
|
||||
logger.info("User VC status changed %s", user.id)
|
||||
logger.info("Before %s", before)
|
||||
logger.info("After %s", after)
|
||||
logger.debug("User VC status changed %s", user.id)
|
||||
logger.debug("Before %s", before)
|
||||
logger.debug("After %s", after)
|
||||
|
||||
|
||||
@commands.command(name="stop_transcribe")
|
||||
async def stop(self, ctx):
|
||||
self.check_data.stop()
|
||||
stop_token = CommunicationObject("STOP",None,None)
|
||||
logger.info("Item added to queue %s %s", self.comm_queue, stop_token)
|
||||
|
||||
await self.comm_queue.put(stop_token)
|
||||
await ctx.voice_client.disconnect()
|
||||
|
||||
async def transcribe_output_queue(self):
|
||||
logger.info("Transcript worker start")
|
||||
logger.info("Transcript uploader start")
|
||||
config = aai.TranscriptionConfig(language_code="pl")
|
||||
transcriber = aai.Transcriber()
|
||||
logger.info("Transcriber queue id: %s",id(self.comm_queue))
|
||||
logger.debug("Transcriber queue id: %s",id(self.comm_queue))
|
||||
|
||||
while True:
|
||||
logger.info("waiting for tasks")
|
||||
logger.debug("waiting for tasks")
|
||||
item = await self.comm_queue.get()
|
||||
logger.info("Got %s", item)
|
||||
logger.debug("Got %s", item)
|
||||
if "STOP" in item.type:
|
||||
logger.info("Queue ended")
|
||||
logger.debug("Queue ended")
|
||||
break
|
||||
elif "send_file" in item.type:
|
||||
logger.info("Sending file for transcription")
|
||||
logger.debug("Sending file for transcription")
|
||||
transcript = None
|
||||
for iter in item.data:
|
||||
logger.info("Iter %s",iter)
|
||||
try:
|
||||
coro = asyncio.to_thread(
|
||||
transcriber.transcribe,
|
||||
@@ -227,7 +217,6 @@ class Transcriber(commands.Cog):
|
||||
transcript = await coro
|
||||
except Exception as e:
|
||||
logger.warn("Exceptiom occured %s", e)
|
||||
logger.info("Data sent")
|
||||
await self.mc.send(f"{item.user} : {transcript.text}")
|
||||
if transcript.error:
|
||||
logger.error(transcript.error)
|
||||
@@ -236,12 +225,9 @@ class Transcriber(commands.Cog):
|
||||
logger.info("User %s disconnected - cleanup action")
|
||||
else:
|
||||
logger.warn("Something went wrong with object %s", item)
|
||||
logger.info("End transcript worker")
|
||||
logger.info("Transcript uploader stoped")
|
||||
|
||||
async def setup(bot):
|
||||
logger = logging.getLogger("discord")
|
||||
await bot.add_cog(Transcriber(bot))
|
||||
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.
|
||||
# 2. Transkrypcja to abstrakt - w zależności od tego która metoda jest włączona wysyła do odpowiedniego silnika, silniki offline odpalam na activcomie. Zaczynamy od assemblyai bo najlepiej wspiera polski. Potem zobaczymy co dalej.
|
||||
|
||||
Reference in New Issue
Block a user