mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
# 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.hybrid_command(name="witaj")
|
|
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}")
|
|
|
|
async def setup(bot):
|
|
await bot.add_cog(Transcriber(bot)) |