settings optimization

This commit is contained in:
Serge Zaigraeff
2025-03-04 16:29:36 +03:00
parent cbbbbabe23
commit 1af3ebd80e
3 changed files with 14 additions and 9 deletions
+1
View File
@@ -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 |
+8 -5
View File
@@ -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)}")
+5 -4
View File
@@ -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"
}