mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
tst
This commit is contained in:
+17
-14
@@ -7,6 +7,7 @@ from discord.ext import commands, voice_recv, tasks
|
||||
from discord.opus import Decoder as OpusDecoder
|
||||
from queue import Queue, Empty
|
||||
import time
|
||||
import threading
|
||||
# Replace with your API key
|
||||
aai.settings.api_key = "aa9962f0088a449a9c4ab2361e96cc08"
|
||||
discord.opus._load_default()
|
||||
@@ -20,6 +21,7 @@ SAMPLING_RATE = OpusDecoder.SAMPLING_RATE
|
||||
logger = logging.getLogger("discord")
|
||||
location = "/home/pi/Conjurer/transcripts/"
|
||||
|
||||
|
||||
class WaveWriter:
|
||||
def __init__(self, user_id, queue):
|
||||
self.queue = queue
|
||||
@@ -123,24 +125,12 @@ class SRBuffer(voice_recv.AudioSink):
|
||||
logger.warning("WaveSink got error closing file on cleanup", exc_info=True)
|
||||
|
||||
|
||||
class TranscriptionOutput(commands.Cog):
|
||||
def __init__(self, bot, queue):
|
||||
self.bot = bot
|
||||
self.queue = queue
|
||||
self.work = False
|
||||
@tasks.loop(minutes=4600)
|
||||
async def scan_loop(self):
|
||||
while self.work:
|
||||
asyncio.sleep(1.0)
|
||||
logger.info("Output scan loop exited succesfully")
|
||||
|
||||
class Transcriber(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.threads = []
|
||||
self.comm_queue = Queue()
|
||||
self.wsink = SRBuffer(self.comm_queue)
|
||||
self.output_handler = TranscriptionOutput(self.bot, self.comm_queue)
|
||||
async def transcribe(self,file_url):
|
||||
config = aai.TranscriptionConfig(speaker_labels=True, language_code="pl")
|
||||
|
||||
@@ -168,7 +158,6 @@ class Transcriber(commands.Cog):
|
||||
self.output_handler.scan_loop.start()
|
||||
|
||||
vc.listen(self.wsink)
|
||||
self.check_data.start()
|
||||
|
||||
@tasks.loop(seconds=0.5)
|
||||
async def check_data(self):
|
||||
@@ -221,8 +210,22 @@ class Transcriber(commands.Cog):
|
||||
self.check_data.stop()
|
||||
await ctx.voice_client.disconnect()
|
||||
|
||||
|
||||
async def transcribe_output_queue():
|
||||
while True:
|
||||
asyncio.sleep(10.0)
|
||||
logger.info("PING")
|
||||
async def setup(bot):
|
||||
logger = logging.getLogger("discord")
|
||||
logger.info("Started comms")
|
||||
threads = []
|
||||
#threads.append(threading.Thread(target=flask_debug))
|
||||
threads.append(threading.Thread(target=transcribe_output_queue))
|
||||
|
||||
for worker in threads:
|
||||
worker.start()
|
||||
for worker in threads:
|
||||
worker.join()
|
||||
|
||||
await bot.add_cog(Transcriber(bot))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user