|
import librosa
|
|
import numpy as np
|
|
from scipy.signal import butter, filtfilt
|
|
|
|
class AudioProcessor:
|
|
@staticmethod
|
|
def load_and_process_audio(file_path, target_sr=16000):
|
|
"""加载并处理音频文件"""
|
|
|
|
audio_data, sr = librosa.load(file_path, sr=target_sr)
|
|
|
|
|
|
audio_data = librosa.util.normalize(audio_data)
|
|
|
|
return audio_data
|
|
|
|
@staticmethod
|
|
def resample(audio_data, orig_sr, target_sr=16000):
|
|
"""重采样音频"""
|
|
return librosa.resample(audio_data, orig_sr=orig_sr, target_sr=target_sr)
|
|
|
|
@staticmethod
|
|
def denoise(audio_data, sr):
|
|
"""音频降噪"""
|
|
|
|
return audio_data
|
|
|
|
@staticmethod
|
|
def normalize(audio_data):
|
|
"""音频归一化"""
|
|
return librosa.util.normalize(audio_data) |