transcribe-bot/transcribebot.py

27 lines
911 B
Python
Raw Normal View History

2023-04-15 13:29:24 +00:00
import disnake
from disnake.ext import commands
from dotenv import load_dotenv
import os
2023-04-15 13:58:19 +00:00
from os import path
from pydub import AudioSegment
import speech_recognition as sr
2023-04-15 13:29:24 +00:00
2023-04-15 13:58:19 +00:00
st = sr.Recognizer()
2023-04-15 13:29:24 +00:00
load_dotenv()
bot = commands.Bot(command_prefix='.')
@bot.message_command(name="Transcrible")
async def transcribe(inter: disnake.ApplicationCommandInteraction, message: disnake.Message):
2023-04-15 14:14:54 +00:00
await inter.response.defer(ephemeral='true')
2023-04-15 13:29:24 +00:00
# Reversing the message and sending it back.
2023-04-15 14:07:00 +00:00
await message.attachments[0].save("audio.ogg")
mp3file = AudioSegment.from_ogg("audio.ogg")
2023-04-15 13:58:19 +00:00
mp3file.export("audio.wav", format="wav")
convertemessage = sr.AudioFile("audio.wav")
with convertemessage as sounds:
transcribeaudo = st.record(sounds)
2023-04-15 14:16:16 +00:00
await inter.edit_original_message(st.recognize_sphinx(transcribeaudo))
2023-04-15 14:07:00 +00:00
os.remove("audio.ogg")
2023-04-15 13:58:19 +00:00
os.remove("audio.wav")
2023-04-15 13:29:24 +00:00
bot.run(os.getenv("TOKEN"))