【问题标题】:How to resample a .wav sound file which is being read using the wavfile.read?如何重新采样正在使用 wavfile.read 读取的 .wav 声音文件?
【发布时间】:2021-02-23 04:04:32
【问题描述】:

我想更改以下两行代码:

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

我想使用wavfile.read() 而不是librosa.load() 加载.wav 文件,然后使用libroa.resample() 以外的其他技术对其进行重新采样。

知道怎么做吗?

【问题讨论】:

    标签: python-3.x matplotlib scipy librosa


    【解决方案1】:

    这就是答案,伙计们!以下解决方案对我有用。

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-17
      • 2016-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多