Add more transcription options

This commit is contained in:
insert-usernamehere 2023-04-15 20:00:56 -04:00
parent 035ef71814
commit 113333fd89

View file

@ -10,21 +10,45 @@ st = sr.Recognizer()
load_dotenv() load_dotenv()
bot = commands.Bot(command_prefix='.') bot = commands.Bot(command_prefix='.')
@bot.message_command(name="Transcrible") def prepaudio(audiofile):
async def transcribe(inter: disnake.ApplicationCommandInteraction, message: disnake.Message): oggfile = AudioSegment.from_ogg(audiofile)
oggfile.export(audiofile, format="wav")
convertemessage = sr.AudioFile("audio.wav")
with convertemessage as sounds:
transcribeaudo = st.record(sounds)
return transcribeaudo
@bot.message_command(name="Transcrible Using Sphinx")
async def transcribesphinx(inter: disnake.ApplicationCommandInteraction, message: disnake.Message):
try: try:
await inter.response.defer(ephemeral='true') await inter.response.defer(ephemeral='true')
await message.attachments[0].save("audio.ogg") await message.attachments[0].save("audio.ogg")
mp3file = AudioSegment.from_ogg("audio.ogg") await inter.edit_original_message(content=st.recognize_sphinx(prepaudio("audio.ogg")))
mp3file.export("audio.wav", format="wav")
convertemessage = sr.AudioFile("audio.wav")
with convertemessage as sounds:
transcribeaudo = st.record(sounds)
await inter.edit_original_message(content=st.recognize_sphinx(transcribeaudo))
os.remove("audio.ogg") os.remove("audio.ogg")
os.remove("audio.wav") os.remove("audio.wav")
except Exception as e: except Exception as e:
await inter.edit_original_message(content=f'an error appears to have occoured please report it to the developer: {e}') await inter.edit_original_message(content=f'an error appears to have occoured please report it to the developer: {e}')
@bot.message_command(name="Transcrible Using Google")
async def transcribesphinx(inter: disnake.ApplicationCommandInteraction, message: disnake.Message):
try:
await inter.response.defer(ephemeral='true')
await message.attachments[0].save("audio.ogg")
await inter.edit_original_message(content=st.recognize_google(prepaudio("audio.ogg")))
os.remove("audio.ogg")
os.remove("audio.wav")
except Exception as e:
await inter.edit_original_message(content=f'an error appears to have occoured please report it to the developer: {e}')
@bot.message_command(name="Transcrible Using Bing")
async def transcribesphinx(inter: disnake.ApplicationCommandInteraction, message: disnake.Message):
try:
await inter.response.defer(ephemeral='true')
await message.attachments[0].save("audio.ogg")
await inter.edit_original_message(content=st.recognize_bing(prepaudio("audio.ogg")))
os.remove("audio.ogg")
os.remove("audio.wav")
except Exception as e:
await inter.edit_original_message(content=f'an error appears to have occoured please report it to the developer: {e}')
bot.run(os.getenv("TOKEN")) bot.run(os.getenv("TOKEN"))