WAV降采样
Jan. 25, 2019, 4:18 p.m.
read: 1210
提供三种方案
FFMpeg
./ffmpeg -i in.wav -f wav -ar 16000 -ac 1 out.wav
librosa
y, sr = librosa.load(filename, sr=48000)
y_8k = librosa.resample(y,sr,8000)
scipy
import scipy.signal as signal
import scipy.io.wavfile as wavfile
import numpy as np
def wav_file_resample(file_path, source_sample=44100, dest_sample=16000):
'''
对WAV文件进行resample的操作
: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)
wavfile.write(file_path, dest_sample, x_resampled)