fix
This commit is contained in:
parent
d16b070133
commit
6c6b03a324
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
import uuid
|
import uuid
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from aiogram import types, Dispatcher, F
|
from aiogram import types, Dispatcher, F
|
||||||
|
@ -77,7 +78,7 @@ async def handle_voice_and_video(message: types.Message, redis_service, storage_
|
||||||
else:
|
else:
|
||||||
await message.reply("Sorry, transcription result was not received within the timeout.")
|
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 канал (моно).
|
Конвертирует любой аудио/видеофайл в .wav с частотой 16kHz, 1 канал (моно).
|
||||||
"""
|
"""
|
||||||
|
@ -92,6 +93,30 @@ def convert_to_wav(input_file: str, output_file: str):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error converting {input_file} to WAV: {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):
|
def register_audio_handlers(dp: Dispatcher, redis_service, storage_path: str):
|
||||||
# Оборачиваем callback для передачи дополнительных аргументов
|
# Оборачиваем callback для передачи дополнительных аргументов
|
||||||
handler_callback = partial(handle_voice_and_video, redis_service=redis_service, storage_path=storage_path)
|
handler_callback = partial(handle_voice_and_video, redis_service=redis_service, storage_path=storage_path)
|
||||||
|
|
Loading…
Reference in New Issue