mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
Fx test
This commit is contained in:
+24
-23
@@ -21,6 +21,11 @@ SAMPLING_RATE = OpusDecoder.SAMPLING_RATE
|
||||
logger = logging.getLogger("discord")
|
||||
location = "/home/pi/Conjurer/transcripts/"
|
||||
|
||||
class CommunicationObject:
|
||||
def __init__(self, msg_type, user, data):
|
||||
self.type = msg_type
|
||||
self.user = user
|
||||
self.data = data
|
||||
|
||||
class WaveWriter:
|
||||
def __init__(self, user_id, queue):
|
||||
@@ -67,11 +72,7 @@ class WaveWriter:
|
||||
self.transcript_file_future.setnchannels(CHANNELS)
|
||||
self.transcript_file_future.setsampwidth(SAMPLE_WIDTH)
|
||||
self.transcript_file_future.setframerate(SAMPLING_RATE)
|
||||
operation = {
|
||||
"type": "user_cleanup",
|
||||
"user" : self.user,
|
||||
"filename": self.file_name_present
|
||||
}
|
||||
operation = CommunicationObject(msg_type="send_file",user=self.user,data=[self.file_name_present])
|
||||
logger.info("After rotation")
|
||||
logger.info(self.file_name_present)
|
||||
logger.info(self.file_name_past)
|
||||
@@ -131,13 +132,6 @@ class Transcriber(commands.Cog):
|
||||
self.comm_queue = queue
|
||||
self.worker = worker
|
||||
self.wsink = SRBuffer(self.comm_queue)
|
||||
async def transcribe(self,file_url):
|
||||
config = aai.TranscriptionConfig(speaker_labels=True, language_code="pl")
|
||||
|
||||
transcriber = aai.Transcriber()
|
||||
transcript = transcriber.transcribe(file_url, config=config)
|
||||
for utterance in transcript.utterances:
|
||||
logger.info("Speaker %s : %s", utterance.speaker, utterance.text)
|
||||
|
||||
@commands.hybrid_command(name="transcribe")
|
||||
async def test(self, ctx):
|
||||
@@ -171,7 +165,6 @@ class Transcriber(commands.Cog):
|
||||
item[2] = time.time_ns()
|
||||
item[4] = False
|
||||
item[0].rotate()
|
||||
await self.transcribe(item[0].file_name_past)
|
||||
item[3] = False
|
||||
|
||||
@commands.Cog.listener()
|
||||
@@ -185,11 +178,7 @@ class Transcriber(commands.Cog):
|
||||
self.wsink.on_user_connect(user)
|
||||
elif after.channel is None:
|
||||
logger.info("User %s disconnected from channel %s", user, before.channel.name)
|
||||
operation = {
|
||||
"type": "user_cleanup",
|
||||
"user" : user,
|
||||
"filename": None
|
||||
}
|
||||
operation = CommunicationObject(msg_type="user_cleanup", user=user, data=None)
|
||||
self.comm_queue.put(operation)
|
||||
else:
|
||||
logger.info("User VC status changed %s", user.id)
|
||||
@@ -200,22 +189,34 @@ class Transcriber(commands.Cog):
|
||||
@commands.command(name="stop_transcribe")
|
||||
async def stop(self, ctx):
|
||||
self.check_data.stop()
|
||||
self.comm_queue.put("STOP")
|
||||
stop_token = CommunicationObject("STOP",None,None)
|
||||
self.comm_queue.put(stop_token)
|
||||
await ctx.voice_client.disconnect()
|
||||
|
||||
def transcribe_output_queue(queue):
|
||||
logger.info("Worker start")
|
||||
logger.info("Transcript worker start")
|
||||
config = aai.TranscriptionConfig(speaker_labels=True, language_code="pl")
|
||||
transcriber = aai.Transcriber()
|
||||
while True:
|
||||
item = queue.get()
|
||||
if item == "STOP":
|
||||
if item.type == "STOP":
|
||||
logger.info("Queue ended")
|
||||
break
|
||||
logger.info("PING")
|
||||
elif item.type == "send_file":
|
||||
transcript = ""
|
||||
for iter in item.data:
|
||||
transcript = transcriber.transcribe(iter, config=config)
|
||||
for utterance in transcript.utterances:
|
||||
logger.info("%s : %s", item.user, utterance.text)
|
||||
elif item.type == "user_cleanup":
|
||||
logger.info("User %s disconnected - cleanup action")
|
||||
logger.info("End transcript worker")
|
||||
|
||||
async def setup(bot):
|
||||
logger = logging.getLogger("discord")
|
||||
logger.info("Loading voice transcribed module phase one")
|
||||
worker = threading.Thread(target=transcribe_output_queue)
|
||||
logger.info("Loading voice transcribed phase two")
|
||||
logger.info("Loading voice transcribed phasetwo")
|
||||
queue = Queue()
|
||||
logger.info("Loading voice transcribed module phase three")
|
||||
await bot.add_cog(Transcriber(bot, worker, queue))
|
||||
|
||||
Reference in New Issue
Block a user