This commit is contained in:
itqop 2025-02-23 20:11:12 +03:00
parent d16b070133
commit 6c6b03a324
1 changed files with 26 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import os
import subprocess
import uuid
from functools import partial
from aiogram import types, Dispatcher, F
@ -77,7 +78,7 @@ async def handle_voice_and_video(message: types.Message, redis_service, storage_
else:
await message.reply("Sorry, transcription result was not received within the timeout.")
def convert_to_wav(input_file: str, output_file: str):
def convert_to_wav1(input_file: str, output_file: str):
"""
Конвертирует любой аудио/видеофайл в .wav с частотой 16kHz, 1 канал (моно).
"""
@ -92,6 +93,30 @@ def convert_to_wav(input_file: str, output_file: str):
except Exception as e:
print(f"Error converting {input_file} to WAV: {e}")
def convert_to_wav(input_file: str, output_file: str):
"""
Конвертирует любой аудиофайл в WAV с частотой 16kHz, 1 канал (моно).
Логирует ошибки FFmpeg.
"""
try:
logging.debug(f"🔄 Конвертация: {input_file} -> {output_file}")
command = [
"ffmpeg", "-y", "-i", input_file,
"-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le",
output_file
]
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode != 0:
logging.error(f"❌ Ошибка FFmpeg:\n{result.stderr.decode()}")
else:
logging.debug(f"✅ FFmpeg успешно создал файл {output_file}")
except Exception as e:
logging.error(f"❌ Исключение при конвертации {input_file}: {e}")
def register_audio_handlers(dp: Dispatcher, redis_service, storage_path: str):
# Оборачиваем callback для передачи дополнительных аргументов
handler_callback = partial(handle_voice_and_video, redis_service=redis_service, storage_path=storage_path)