更改音频采样率而不影响播放速度

时间:2020-03-12 02:47:36

标签: python performance sampling wave rate

我只是想将音频数据集(.wav格式)的采样率从32000Hz更改为44100Hz,但是这样做,回放速度也改变了(非常可接受且合乎逻辑)。 我的意思是,如何在不更改播放速度的情况下进行此更改? 目前,我正在使用Wave lib来执行此操作。看下面的代码:

import wave
# First i open the file.wav on read mode
opened_audio = wave.open(caminho, 'rb')

# Then i get all information that will be maintained                   
channels = opened_audio.getnchannels()
swidth = opened_audio.getsampwidth()
signal = opened_audio.readframes(-1)
opened_audio.close()

# Here i open the file.wav on write mode
wf = wave.open(caminho, 'wb')

# Then i set all obtained data that will not be changed
wf.setnchannels(channels)
wf.setsampwidth(swidth)
# Here is the new sampling rate in Hz
wf.setframerate(44100)
wf.writeframes(signal)
wf.close()

详细信息:我已经在这里阅读了很多帖子,但是没有人解决问题。

0 个答案:

没有答案