From 5ea792bcd2a5cafb1a7a70895187e612569dae0a Mon Sep 17 00:00:00 2001 From: mtuszowski Date: Thu, 15 Aug 2024 14:11:17 +0200 Subject: [PATCH] Transcribe cog --- bot.py | 2 + conjurer_librarian/voice_recognition.py | 35 ----------------- voice_recognition.py | 51 +++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 35 deletions(-) delete mode 100644 conjurer_librarian/voice_recognition.py create mode 100644 voice_recognition.py diff --git a/bot.py b/bot.py index afd87be..08ca2a5 100644 --- a/bot.py +++ b/bot.py @@ -49,6 +49,7 @@ from communication_subroutine import ( comm_subroutine, PREPPED_TRACKS, ) +import voice_recognition from spotify_dl import spotify from spotify_dl import youtube as youtube_download @@ -291,6 +292,7 @@ logger.info("Done") # *=========================================== Create Client logger.info("Creating discord bot") client = commands.Bot(intents=intents, command_prefix="$") +client.add_cog(voice_recognition.Transcriber(client)) logger.info("Done") logger.info("Creating flask app") logger.info("Done") diff --git a/conjurer_librarian/voice_recognition.py b/conjurer_librarian/voice_recognition.py deleted file mode 100644 index 44a7bd9..0000000 --- a/conjurer_librarian/voice_recognition.py +++ /dev/null @@ -1,35 +0,0 @@ -# Start by making sure the `assemblyai` package is installed. -# If not, you can install it by running the following command: -# pip install -U assemblyai -# -# Note: Some macOS users may need to use `pip3` instead of `pip`. - -import assemblyai as aai -from discord.ext import commands -# Replace with your API key -aai.settings.api_key = "aa9962f0088a449a9c4ab2361e96cc08" - -# 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' - -config = aai.TranscriptionConfig(speaker_labels=True) - -transcriber = aai.Transcriber() -transcript = transcriber.transcribe( - FILE_URL, - config=config -) - -for utterance in transcript.utterances: - print(f"Speaker {utterance.speaker}: {utterance.text}") - - - - -class Transcriber(commands.Cog): - def __init__(self,bot): - self.bot = bot - self._last_member = None \ No newline at end of file diff --git a/voice_recognition.py b/voice_recognition.py new file mode 100644 index 0000000..e11b5ab --- /dev/null +++ b/voice_recognition.py @@ -0,0 +1,51 @@ +# Start by making sure the `assemblyai` package is installed. +# If not, you can install it by running the following command: +# pip install -U assemblyai +# +# Note: Some macOS users may need to use `pip3` instead of `pip`. + +import assemblyai as aai +import discord +from discord.ext import commands +# Replace with your API key +aai.settings.api_key = "aa9962f0088a449a9c4ab2361e96cc08" + +# 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' + + + +class Transcriber(commands.Cog): + def __init__(self, bot): + self.bot = bot + self._last_member = None + + + @commands.Cog.listener() + async def on_member_join(self, member): + channel = member.guild.system_channel + if channel is not None: + await channel.send(f'Witaj u Nas {member.mention}.') + + @commands.command() + async def witaj(self, ctx, *, member: discord.Member = None): + """Says hello""" + member = member or ctx.author + if self._last_member is None or self._last_member.id != member.id: + await ctx.send(f'Mhm {member.name}~') + else: + await ctx.send(f'Powtarzas sie {member.name}') + self._last_member = member + async def transcribe(): + config = aai.TranscriptionConfig(speaker_labels=True) + + transcriber = aai.Transcriber() + transcript = transcriber.transcribe( + FILE_URL, + config=config + ) + for utterance in transcript.utterances: + print(f"Speaker {utterance.speaker}: {utterance.text}")