Add model auto-download and English logging
This commit is contained in:
+11
-11
@@ -66,14 +66,14 @@ class AudioProcessor:
|
||||
output_path
|
||||
]
|
||||
|
||||
logger.debug("Конвертация в WAV: %s", " ".join(cmd))
|
||||
logger.debug("Converting to WAV: %s", " ".join(cmd))
|
||||
|
||||
try:
|
||||
subprocess.run(cmd, check=True, capture_output=True)
|
||||
logger.info("Файл конвертирован в WAV: %s", output_path)
|
||||
logger.info("Converted file to WAV: %s", output_path)
|
||||
return output_path
|
||||
except subprocess.CalledProcessError as e:
|
||||
logger.error("Ошибка при конвертации в WAV: %s", e.stderr.decode())
|
||||
logger.error("Failed to convert to WAV: %s", e.stderr.decode())
|
||||
raise
|
||||
|
||||
def normalize_audio(self, input_path: str) -> str:
|
||||
@@ -101,14 +101,14 @@ class AudioProcessor:
|
||||
"compand"
|
||||
] + self.compand_params.split()
|
||||
|
||||
logger.debug("Нормализация аудио: %s", " ".join(cmd))
|
||||
logger.debug("Normalizing audio: %s", " ".join(cmd))
|
||||
|
||||
try:
|
||||
subprocess.run(cmd, check=True, capture_output=True)
|
||||
logger.info("Аудио нормализовано: %s", output_path)
|
||||
logger.info("Audio normalized: %s", output_path)
|
||||
return output_path
|
||||
except subprocess.CalledProcessError as e:
|
||||
logger.error("Ошибка при нормализации аудио: %s", e.stderr.decode())
|
||||
logger.error("Failed to normalize audio: %s", e.stderr.decode())
|
||||
raise
|
||||
|
||||
def add_silence(self, input_path: str) -> str:
|
||||
@@ -135,14 +135,14 @@ class AudioProcessor:
|
||||
"pad", "2.0", "1.0" # Добавление тишины в начале и в конце (секунды)
|
||||
]
|
||||
|
||||
logger.info("Добавление тишины: %s", " ".join(cmd))
|
||||
logger.info("Adding silence padding: %s", " ".join(cmd))
|
||||
|
||||
try:
|
||||
subprocess.run(cmd, check=True, capture_output=True)
|
||||
logger.info("Тишина добавлена: %s", output_path)
|
||||
logger.info("Silence padding added: %s", output_path)
|
||||
return output_path
|
||||
except subprocess.CalledProcessError as e:
|
||||
logger.error("Ошибка при добавлении тишины: %s", e.stderr.decode())
|
||||
logger.error("Failed to add silence padding: %s", e.stderr.decode())
|
||||
raise
|
||||
|
||||
def process_audio(self, input_path: str) -> Tuple[str, list]:
|
||||
@@ -177,6 +177,6 @@ class AudioProcessor:
|
||||
return silence_path, temp_files
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Ошибка при обработке аудио %s: %s", input_path, e)
|
||||
logger.error("Failed to process audio %s: %s", input_path, e)
|
||||
cleanup_temp_files(temp_files)
|
||||
raise
|
||||
raise
|
||||
|
||||
@@ -104,7 +104,7 @@ def get_url_file(url: str, max_file_size_mb: int = 100) -> Tuple[Optional[str],
|
||||
return temp_path, original_name or os.path.basename(temp_path), None
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Ошибка при получении файла по URL %s: %s", url, e)
|
||||
logger.error("Failed to fetch file from URL %s: %s", url, e)
|
||||
return None, None, f"Error retrieving file from URL: {str(e)}"
|
||||
|
||||
|
||||
@@ -144,5 +144,5 @@ def get_base64_file(base64_data: str, max_file_size_mb: int = 100) -> Tuple[Opti
|
||||
return temp_path, os.path.basename(temp_path), None
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Ошибка при декодировании base64 данных: %s", e)
|
||||
logger.error("Failed to decode base64 data: %s", e)
|
||||
return None, None, f"Error decoding base64 data: {str(e)}"
|
||||
|
||||
+6
-6
@@ -27,7 +27,7 @@ def load_audio(file_path: str, sr: int = 16000) -> Tuple[np.ndarray, int]:
|
||||
try:
|
||||
with wave.open(file_path, 'rb') as wav_file:
|
||||
if wav_file.getnchannels() != 1:
|
||||
logger.warning("Файл %s не моно-аудио", file_path)
|
||||
logger.warning("File %s is not mono audio", file_path)
|
||||
|
||||
frames = wav_file.readframes(-1)
|
||||
audio_array = np.frombuffer(frames, dtype=np.int16).astype(np.float32) / 32768.0
|
||||
@@ -41,7 +41,7 @@ def load_audio(file_path: str, sr: int = 16000) -> Tuple[np.ndarray, int]:
|
||||
return audio_array, sampling_rate
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Ошибка при загрузке аудио %s: %s", file_path, e)
|
||||
logger.error("Failed to load audio %s: %s", file_path, e)
|
||||
raise
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ def get_audio_duration(file_path: str) -> float:
|
||||
Длительность в секундах.
|
||||
"""
|
||||
if not os.path.exists(file_path):
|
||||
raise Exception(f"Файл не существует: {file_path}")
|
||||
raise Exception(f"File does not exist: {file_path}")
|
||||
|
||||
cmd = [
|
||||
"ffprobe",
|
||||
@@ -70,8 +70,8 @@ def get_audio_duration(file_path: str) -> float:
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, check=True, timeout=10)
|
||||
return float(result.stdout.strip())
|
||||
except subprocess.TimeoutExpired:
|
||||
raise Exception(f"Таймаут при определении длительности файла {file_path}")
|
||||
raise Exception(f"Timed out while determining duration for file {file_path}")
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise Exception(f"Ошибка ffprobe для файла {file_path}: {e.stderr}")
|
||||
raise Exception(f"ffprobe error for file {file_path}: {e.stderr}")
|
||||
except (ValueError, TypeError) as e:
|
||||
raise Exception(f"Ошибка при преобразовании длительности для файла {file_path}: {e}")
|
||||
raise Exception(f"Failed to parse duration for file {file_path}: {e}")
|
||||
|
||||
Reference in New Issue
Block a user