c8163cbadc
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 24s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 29s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 54s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 7s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m37s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m55s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 2m37s
AI Code Review / AI Code Review (pull_request) Successful in 1m43s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m4s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Successful in 26s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 3m4s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m17s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 3m35s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 6m44s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 7m16s
74 lines
2.5 KiB
Python
Executable File
74 lines
2.5 KiB
Python
Executable File
"""音频降噪引擎 — 基于 FFmpeg afftdn 滤镜.
|
||
|
||
支持对音频进行背景噪音消除、人声增强,适用于语音录制、采访等场景。
|
||
|
||
领域模型已抽离至 packages/domain/noise_reduction_config.py,本模块保留薄包装以维持向后兼容。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import logging
|
||
|
||
from packages.domain.noise_reduction_config import (
|
||
NoiseReductionConfig,
|
||
)
|
||
from packages.domain.noise_reduction_config import (
|
||
apply_noise_reduction_if_needed as _apply_noise_reduction_if_needed_base,
|
||
)
|
||
from packages.domain.noise_reduction_config import build_afftdn_filter as _build_afftdn_filter_base # noqa: F401 — 向后兼容
|
||
from packages.domain.noise_reduction_config import build_arnndn_filter as _build_arnndn_filter_base
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
|
||
class NoiseReductionEngine:
|
||
"""音频降噪引擎 — 薄包装,实际逻辑在 domain.noise_reduction_config.
|
||
|
||
基于 FFmpeg afftdn(Audio FFt Denoiser)滤镜实现:
|
||
- 使用短时傅里叶变换分析音频频谱
|
||
- 识别并消除稳态背景噪音
|
||
- 保留人声等非稳态信号
|
||
"""
|
||
|
||
def __init__(self, config: NoiseReductionConfig):
|
||
self.config = config
|
||
|
||
def build_filter(self, input_label: str, output_label: str) -> str:
|
||
"""构建音频降噪滤镜字符串.
|
||
|
||
Args:
|
||
input_label: 输入标签,如 "[0:a]" 或 "[a0]"
|
||
output_label: 输出标签,如 "[nr0]"
|
||
|
||
Returns:
|
||
FFmpeg 滤镜字符串
|
||
"""
|
||
return _build_afftdn_filter_base(self.config, input_label, output_label)
|
||
|
||
def build_filter_arnndn(self, input_label: str, output_label: str, model_file: str) -> str:
|
||
"""使用 RNN 降噪滤镜(arnndn,效果更好但需要模型文件).
|
||
|
||
Args:
|
||
input_label: 输入标签
|
||
output_label: 输出标签
|
||
model_file: RNNNoise 模型文件路径
|
||
|
||
Returns:
|
||
FFmpeg 滤镜字符串
|
||
"""
|
||
return _build_arnndn_filter_base(self.config, input_label, output_label, model_file)
|
||
|
||
|
||
def apply_noise_reduction_if_needed(config_data, input_label: str, output_label: str):
|
||
"""便捷函数:根据配置判断是否需要应用音频降噪.
|
||
|
||
Args:
|
||
config_data: 降噪配置字典
|
||
input_label: 输入标签
|
||
output_label: 输出标签
|
||
|
||
Returns:
|
||
滤镜字符串,不需要降噪时返回 None
|
||
"""
|
||
return _apply_noise_reduction_if_needed_base(config_data, input_label, output_label)
|