Files
dataset-tg-bot/src/audio.py
Arity-T 8fecb3d543 feat: add FSM handlers and admin interface
- Add all user FSM states (INTRO through CONFIRM_SAVE)
- Add replica re-recording by number (ASK_REPLICA_NUMBER, REPEAT_REPLICA)
- Add admin interface with stats and scenario upload
- Add voice message handling and storage
2026-02-02 21:25:19 +03:00

32 lines
926 B
Python

from telegram import Bot
from src.config import DATA_PARTIAL_DIR
from src.database import upsert_recording
from src.logger import logger
from src.scenarios import get_audio_filename
async def save_voice_message(
bot: Bot,
file_id: str,
user_id: int,
scenario_id: str,
replica_index: int,
) -> None:
"""Сохраняет голосовое сообщение в data_partial/."""
# Создаём директорию если нужно
scenario_dir = DATA_PARTIAL_DIR / scenario_id
scenario_dir.mkdir(parents=True, exist_ok=True)
# Скачиваем файл
file = await bot.get_file(file_id)
filename = get_audio_filename(replica_index, user_id)
filepath = scenario_dir / filename
await file.download_to_drive(filepath)
# Записываем в БД
upsert_recording(user_id, scenario_id, replica_index)
logger.debug(f"Saved voice: {filepath}")