From 1af3ebd80ed4266ea4c425d9694b97b905ab6d0c Mon Sep 17 00:00:00 2001 From: Serge Zaigraeff Date: Tue, 4 Mar 2025 16:29:36 +0300 Subject: [PATCH] settings optimization --- README.md | 1 + app/audio_processor.py | 13 ++++++++----- config.json | 9 +++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6a0edfe..7ce358e 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ The service is configured through the `config.json` file: | `batch_size` | Batch size for processing | | `max_new_tokens` | Maximum new tokens for the model output | | `return_timestamps` | Whether to return timestamps in the transcription | +| `audio_rate` | Audio sampling rate in Hz | | `norm_level` | Normalization level for audio preprocessing | | `compand_params` | Parameters for audio compression/expansion | diff --git a/app/audio_processor.py b/app/audio_processor.py index 45be012..2c800c6 100644 --- a/app/audio_processor.py +++ b/app/audio_processor.py @@ -38,18 +38,21 @@ class AudioProcessor: Returns: Путь к сконвертированному WAV-файлу. """ + + audio_rate = self.config["audio_rate"] + # Проверка расширения файла if input_path.lower().endswith('.wav'): # Проверяем, нужно ли преобразовывать WAV-файл (например, если частота не 16 кГц) try: info = subprocess.check_output(['soxi', input_path]).decode() - if '16000 Hz' in info: - logger.info(f"Файл {input_path} уже в формате WAV с частотой 16 кГц") + if f'{audio_rate} Hz' in info: + logger.info(f"Файл {input_path} уже в формате WAV с частотой {audio_rate} Гц") return input_path except subprocess.CalledProcessError: logger.warning(f"Не удалось получить информацию о WAV-файле {input_path}") # Продолжаем конвертацию, чтобы быть уверенными в формате - + # Создаем временный файл для WAV temp_dir = tempfile.mkdtemp() output_path = os.path.join(temp_dir, f"{uuid.uuid4()}.wav") @@ -60,7 +63,7 @@ class AudioProcessor: "-hide_banner", "-loglevel", "warning", "-i", input_path, - "-ar", "16000", + "-ar", f"{audio_rate}", "-ac", "1", # Монофонический звук output_path ] @@ -127,7 +130,7 @@ class AudioProcessor: "sox", input_path, output_path, - "pad", "2.0" # 2 секунды тишины в начале + "pad", "2.0", "1.0" # Добавление тишины в начале и в конце (секунды) ] logger.info(f"Добавление тишины: {' '.join(cmd)}") diff --git a/config.json b/config.json index e3db5a2..7f7f0f9 100644 --- a/config.json +++ b/config.json @@ -3,10 +3,11 @@ "model_path": "/mnt/cloud/llm/whisper/whisper-large-v3-russian", "language": "russian", "enable_history": true, - "chunk_length_s": 30, - "batch_size": 16, - "max_new_tokens": 256, + "chunk_length_s": 22, + "batch_size": 20, + "max_new_tokens": 384, "return_timestamps": false, + "audio_rate": 8000, "norm_level": "-0.5", - "compand_params": "0.3,1 -90,-90,-70,-70,-60,-20,0,0 -5 0 0.2" + "compand_params": "0.3,1 -90,-90,-70,-50,-40,-15,0,0 -7 0 0.15" } \ No newline at end of file