mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-17 07:12:09 +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 discord.opus import Decoder as OpusDecoder
|
||||||
from queue import Queue, Empty
|
from queue import Queue, Empty
|
||||||
import time
|
import time
|
||||||
|
import threading
|
||||||
# Replace with your API key
|
# Replace with your API key
|
||||||
aai.settings.api_key = "aa9962f0088a449a9c4ab2361e96cc08"
|
aai.settings.api_key = "aa9962f0088a449a9c4ab2361e96cc08"
|
||||||
discord.opus._load_default()
|
discord.opus._load_default()
|
||||||
@@ -20,6 +21,7 @@ SAMPLING_RATE = OpusDecoder.SAMPLING_RATE
|
|||||||
logger = logging.getLogger("discord")
|
logger = logging.getLogger("discord")
|
||||||
location = "/home/pi/Conjurer/transcripts/"
|
location = "/home/pi/Conjurer/transcripts/"
|
||||||
|
|
||||||
|
|
||||||
class WaveWriter:
|
class WaveWriter:
|
||||||
def __init__(self, user_id, queue):
|
def __init__(self, user_id, queue):
|
||||||
self.queue = 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)
|
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):
|
class Transcriber(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.threads = []
|
self.threads = []
|
||||||
self.comm_queue = Queue()
|
self.comm_queue = Queue()
|
||||||
self.wsink = SRBuffer(self.comm_queue)
|
self.wsink = SRBuffer(self.comm_queue)
|
||||||
self.output_handler = TranscriptionOutput(self.bot, 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")
|
||||||
|
|
||||||
@@ -168,7 +158,6 @@ class Transcriber(commands.Cog):
|
|||||||
self.output_handler.scan_loop.start()
|
self.output_handler.scan_loop.start()
|
||||||
|
|
||||||
vc.listen(self.wsink)
|
vc.listen(self.wsink)
|
||||||
self.check_data.start()
|
|
||||||
|
|
||||||
@tasks.loop(seconds=0.5)
|
@tasks.loop(seconds=0.5)
|
||||||
async def check_data(self):
|
async def check_data(self):
|
||||||
@@ -221,8 +210,22 @@ class Transcriber(commands.Cog):
|
|||||||
self.check_data.stop()
|
self.check_data.stop()
|
||||||
await ctx.voice_client.disconnect()
|
await ctx.voice_client.disconnect()
|
||||||
|
|
||||||
|
async def transcribe_output_queue():
|
||||||
|
while True:
|
||||||
|
asyncio.sleep(10.0)
|
||||||
|
logger.info("PING")
|
||||||
async def setup(bot):
|
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))
|
await bot.add_cog(Transcriber(bot))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user