how can i send telegram voice file to whisper effective and correct?

49 Views Asked by At

I need to send a voice message from user to whisper without saving anywhere.I tried to use save file in buffer, and then i send this file to whisper also using librosa(found this decision in forum), but response is empty and timeout of request about 15-20 seconds. What can i do?

async def transcribe_audio(self, audio_file) -> str:
    model = whisper.load_model("medium")
    audio_file, sr = librosa.load(audio_file)
    if sr != 1600:
        audio_file = librosa.resample(audio_file, orig_sr=sr, target_sr=1600)
    response = model.transcribe(audio_file, fp16=False,language="russian")
    print(response)
    return response["text"]
async def voice_message_handler(message: Message):
    voice_file = await bot.get_file(message.voice.file_id)
    buf = io.BytesIO()
    await bot.download_file(voice_file.file_path, buf)
    buf.name = f"{message.from_user.id}.ogg"
    buf.seek(0)
    prompt = await chatbot.transcribe_audio(buf)

I get this:

{'text': '', 'segments': [], 'language': 'russian'}
ERROR:aiogram.dispatcher:Failed to fetch updates - TelegramNetworkError: HTTP Client says - Request timeout error
WARNING:aiogram.dispatcher:Sleep for 1.000000 seconds and try again... (tryings = 0, bot id = 6766855504)
0

There are 0 best solutions below