aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py33
1 files changed, 31 insertions, 2 deletions
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, "файл не вошёл❌")