How to resample a .wav sound file which is being read using the wavfile.read?

﹥>﹥吖頭↗ 提交于 2021-02-11 12:54:25

问题


I want to change the following two lines of my code:

clip, sample_rate = librosa.load(file_name)
clip = librosa.resample(clip, sample_rate, 2000)

I want to load the .wav file using wavfile.read() instead of using librosa.load() and then resample it using some technique other than the libroa.resample().

Any idea how to do it?


回答1:


So here is the answer folks! The below solution worked for me.

from scipy.io import wavfile
import scipy.signal as sps
from io import BytesIO

new_rate = 2000
# Read file
sample_rate, clip = wavfile.read(BytesIO(file_name))
       
# Resample data
number_of_samples = round(len(clip) * float(new_rate) / sample_rate)
clip = sps.resample(clip, number_of_samples)


来源:https://stackoverflow.com/questions/64782091/how-to-resample-a-wav-sound-file-which-is-being-read-using-the-wavfile-read

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!