Initial commit: UMB Telegram Bot
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import logging
|
||||
|
||||
from aiogram import Router, F
|
||||
from aiogram.types import Message
|
||||
|
||||
from bot.utils.voice import download_voice, convert_to_wav, transcribe_audio, normalize_text, cleanup_files
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
router = Router()
|
||||
|
||||
|
||||
@router.message(F.voice)
|
||||
async def handle_voice(message: Message):
|
||||
status_msg = await message.answer("🎤 Распознаю речь...")
|
||||
|
||||
ogg_path = None
|
||||
wav_path = None
|
||||
|
||||
try:
|
||||
ogg_path = await download_voice(message.bot, message.voice.file_id)
|
||||
wav_path = await convert_to_wav(ogg_path)
|
||||
text = await transcribe_audio(wav_path)
|
||||
|
||||
if not text:
|
||||
await status_msg.edit_text("❌ Не удалось распознать речь.")
|
||||
return
|
||||
|
||||
text = normalize_text(text)
|
||||
await status_msg.edit_text(f"📝 {text}")
|
||||
|
||||
except Exception as e:
|
||||
logger.exception("Voice processing error")
|
||||
await status_msg.edit_text("❌ Ошибка при обработке голосового сообщения.")
|
||||
finally:
|
||||
await cleanup_files(ogg_path, wav_path)
|
||||
Reference in New Issue
Block a user