parent
5feb9e0adc
commit
75ae2e439b
1 changed files with 13 additions and 14 deletions
|
@ -6,7 +6,6 @@ import asyncio
|
|||
from pydub import AudioSegment
|
||||
import numpy as np
|
||||
import speech_recognition as sr
|
||||
import whisper
|
||||
|
||||
def prepaudio(audiofile):
|
||||
st = sr.Recognizer()
|
||||
|
@ -22,21 +21,21 @@ class transcription(commands.Cog):
|
|||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
self.st = sr.Recognizer()
|
||||
self.model = whisper.load_model("base")
|
||||
|
||||
|
||||
@nextcord.message_command(name="Transcribe Using Whisper")
|
||||
async def transcribewhisper(self, interaction: nextcord.Interaction, message: nextcord.Message):
|
||||
@nextcord.message_command(name="Transcribe Using Sphinx")
|
||||
async def transcribesphinx(self, interaction: nextcord.Interaction, message: nextcord.Message):
|
||||
try:
|
||||
await interaction.response.defer(ephemeral='true')
|
||||
await message.attachments[0].save("audio.ogg")
|
||||
oggfile = AudioSegment.from_ogg("audio.ogg")
|
||||
oggfile.export("audio.mp3", format="mp3")
|
||||
embed=nextcord.Embed(title="Audio Transcription",description=self.model.transcribe("audio.mp3")["text"], color=0x3584e4)
|
||||
embed=nextcord.Embed(title="Audio Transcription",description=self.st.recognize_sphinx(prepaudio("audio.ogg")), color=0x3584e4)
|
||||
embed.set_author(name=message.author.display_name, url=message.jump_url, icon_url=message.author.display_avatar)
|
||||
embed.set_footer(text="Accuracy not guaranteed")
|
||||
await interaction.edit_original_message(embed=embed)
|
||||
os.remove("audio.ogg")
|
||||
os.remove("audio.mp3")
|
||||
os.remove("audio.wav")
|
||||
except Exception as e:
|
||||
await interaction.edit_original_message(content=f'an error appears to have occoured please report it to the developer: {e}')
|
||||
|
||||
@nextcord.message_command(name="Transcribe Using Google")
|
||||
async def transcribegoogle(self, interaction: nextcord.Interaction, message: nextcord.Message):
|
||||
|
|
Loading…
Reference in a new issue