mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
Events
This commit is contained in:
+43
-25
@@ -10,13 +10,47 @@ aai.settings.api_key = "aa9962f0088a449a9c4ab2361e96cc08"
|
||||
discord.opus._load_default()
|
||||
|
||||
# URL of the file to transcribe
|
||||
FILE_URL = "https://github.com/AssemblyAI-Community/audio-examples/raw/main/20230607_me_canadian_wildfires.mp3"
|
||||
|
||||
# You can also transcribe a local file by passing in a file path
|
||||
# FILE_URL = './path/to/file.mp3'
|
||||
# FILE_URL = './path/to/file.mWp3
|
||||
|
||||
logger = logging.getLogger("discord")
|
||||
location = "/home/pi/Conjurer/"
|
||||
class Events(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_voice_state_update(self, before, after):
|
||||
logger.info("before %s", before)
|
||||
logger.info("after %s", after)
|
||||
|
||||
|
||||
class UserTranscript():
|
||||
def __init__(self, user_id):
|
||||
|
||||
self.username = str(user_id)
|
||||
self.present_file_id = 0
|
||||
self.file_name_past = None
|
||||
|
||||
self.file_name_present = location + self.username + str(self.present_file_id)
|
||||
self.transcript_file_present = wave.Wave_write = wave.open(self.file_name_present, 'wb')
|
||||
|
||||
self.file_name_future = location + self.username + str(self.present_file_id+1)
|
||||
self.transcript_file_future = wave.Wave_write = wave.open(self.file_name_future, 'wb')
|
||||
def rotate(self):
|
||||
self.transcript_file_present.close()
|
||||
self.name_file_past = self.file_name_present
|
||||
self.present_file_id += 1
|
||||
self.file_name_present = self.file_name_future
|
||||
self.transcript_file_present = self.transcript_file_future
|
||||
self.transcript_file_future = location + self.username + str(self.present_file_id+1)
|
||||
self.transcript_file_future = wave.Wave_write = wave.open(self.file_name_future, 'wb')
|
||||
#send past to transcription
|
||||
|
||||
def cleanup(self):
|
||||
self.transcript_file_present.close()
|
||||
self.transcript_file_future.close()
|
||||
#send present to transcription
|
||||
|
||||
class SRBuffer(voice_recv.AudioSink):
|
||||
"""Endpoint AudioSink that generates a wav file.
|
||||
@@ -27,22 +61,10 @@ class SRBuffer(voice_recv.AudioSink):
|
||||
SAMPLE_WIDTH = OpusDecoder.SAMPLE_SIZE // OpusDecoder.CHANNELS
|
||||
SAMPLING_RATE = OpusDecoder.SAMPLING_RATE
|
||||
|
||||
##on member join - 5 plików buforowych na człowieka otwarty jest tylko aktualny i następny
|
||||
#on member join dodajemytypa do listy
|
||||
#on member disconnect - dropujemy go
|
||||
|
||||
|
||||
# event: BasicSinkWriteCB,
|
||||
# rtcp_event: Optional[BasicSinkWriteRTCPCB] = None,
|
||||
# self.cb = event
|
||||
# self.cb_rtcp = rtcp_event
|
||||
# def write(self, user: Optional[User], data: VoiceData) -> None:
|
||||
# self.cb(user, data)
|
||||
# @AudioSink.listener()
|
||||
# def on_rtcp_packet(self, packet: RTCPPacket, guild: discord.Guild) -> None:
|
||||
# self.cb_rtcp(packet) if self.cb_rtcp else None
|
||||
|
||||
|
||||
|
||||
def __init__(self, destination):
|
||||
super().__init__()
|
||||
|
||||
@@ -50,7 +72,7 @@ class SRBuffer(voice_recv.AudioSink):
|
||||
self._file.setnchannels(self.CHANNELS)
|
||||
self._file.setsampwidth(self.SAMPLE_WIDTH)
|
||||
self._file.setframerate(self.SAMPLING_RATE)
|
||||
self.user_list = []
|
||||
self.user_list = {}
|
||||
|
||||
def wants_opus(self) -> bool:
|
||||
return False
|
||||
@@ -67,22 +89,18 @@ class SRBuffer(voice_recv.AudioSink):
|
||||
logger.warning("WaveSink got error closing file on cleanup", exc_info=True)
|
||||
|
||||
|
||||
|
||||
class Transcriber(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
def callback(user, data):
|
||||
logger.info(f"Got packet from {user}")
|
||||
|
||||
self.bot = bot
|
||||
self._last_member = None
|
||||
self.wsink = SRBuffer(destination="/home/pi/Conjurer/wav.wav")
|
||||
|
||||
async def transcribe():
|
||||
config = aai.TranscriptionConfig(speaker_labels=True)
|
||||
async def transcribe(file_url):
|
||||
config = aai.TranscriptionConfig(speaker_labels=True, language_code="pl")
|
||||
|
||||
transcriber = aai.Transcriber()
|
||||
transcript = transcriber.transcribe(
|
||||
FILE_URL,
|
||||
file_url,
|
||||
config=config
|
||||
)
|
||||
for utterance in transcript.utterances:
|
||||
@@ -101,7 +119,7 @@ class Transcriber(commands.Cog):
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(Transcriber(bot))
|
||||
|
||||
await bot.add_cog(Events(bot))
|
||||
|
||||
#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