WAV降采样方式横向评测
Nov. 17, 2019, 5:36 p.m.
read: 1404
# scipy.signal 进行降采样
def wav_file_resample(sig, source_sample=44100, dest_sample=16000):
try:
signal.resample
except:
from scipy import signal
'''
对WAV文件进行resample的操作
!!!注意:sig必须是np.int16格式
:param file_path: 需要进行resample操作的wav文件的路径
:param source_sample:
:param dest_sample:
:return:
'''
# sample_rate, sig = wavfile.read(file_path)
# print(sample_rate)
# print(sig)
result = int((sig.shape[0]) / source_sample * dest_sample)
x_resampled = signal.resample(sig, result)
x_resampled = x_resampled.astype(np.int16)
return x_resampled