Transcribe cog

This commit is contained in:
2024-08-15 14:11:17 +02:00
parent 1d520c4aeb
commit 5ea792bcd2
3 changed files with 53 additions and 35 deletions
+2
View File
@@ -49,6 +49,7 @@ from communication_subroutine import (
comm_subroutine, comm_subroutine,
PREPPED_TRACKS, PREPPED_TRACKS,
) )
import voice_recognition
from spotify_dl import spotify from spotify_dl import spotify
from spotify_dl import youtube as youtube_download from spotify_dl import youtube as youtube_download
@@ -291,6 +292,7 @@ logger.info("Done")
# *=========================================== Create Client # *=========================================== Create Client
logger.info("Creating discord bot") logger.info("Creating discord bot")
client = commands.Bot(intents=intents, command_prefix="$") client = commands.Bot(intents=intents, command_prefix="$")
client.add_cog(voice_recognition.Transcriber(client))
logger.info("Done") logger.info("Done")
logger.info("Creating flask app") logger.info("Creating flask app")
logger.info("Done") logger.info("Done")
-35
View File
@@ -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
+51
View File
@@ -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}")