fix def config, file reading and add vosk api support
This commit is contained in:
1 parent
631fabf30d
commit
99dbfad460
3 files changed
+70
-20
No files matched your search
@@ -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, "файл не вошёл❌")
|
||||
|
||||
Reference in new issue
Block a user