From 99dbfad460e725d49b633665d164c24b3b1b5ec1 Mon Sep 17 00:00:00 2001 From: huker667 Date: Wed, 15 Jul 2026 21:07:09 +0300 Subject: fix def config, file reading and add vosk api support --- main.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index 2b2aa94..68400cd 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import asyncio +import requests import base64 import io import sys @@ -143,6 +144,34 @@ async def guest_middleware(handler, event, data): prompt = "" images = [] + + voice = None + + if VOSK_API != "": + if message.voice: + voice = message.voice + elif replied and replied.voice: + voice = replied.voice + + if voice: + if voice.duration > 60: + da = "не врат не пойдёт такой длинный голосовой сообщение" \ + ". \nнадо меньше 60 секунд da✅" + if event.guest_message: + await g_answer(data, message, da) + else: + await message.reply(da) + buf = BytesIO() + await bot.download(voice, destination=buf) + buf.seek(0) + + result = await asyncio.to_thread( + send_to_vosk, + buf.read() + ) + + prompt = f"<голосовое сообщение>{result.get('text', 'не распознано')}{prompt}" + if message.document: if message.document.file_size > 4096: @@ -161,7 +190,7 @@ async def guest_middleware(handler, event, data): file_content = file_bytes.read().decode("utf-8", errors="ignore") file_bytes.close() - prompt = f"<файл>{file_content}" + prompt = f"<файл>{file_content}{prompt}" except UnicodeDecodeError: if event.guest_message: @@ -191,7 +220,7 @@ async def guest_middleware(handler, event, data): await bot.download(replied.document, destination=file_bytes) file_bytes.seek(0) file_content = file_bytes.read().decode("utf-8", errors="ignore") - prompt = f"<файл>{file_content}{user_text}" + prompt = f"<файл>{file_content}{prompt}" except UnicodeDecodeError: if event.guest_message: await g_answer(data, message, "файл не вошёл❌") -- cgit v1.3.1