下采样 wav 音频文件 [英] Downsampling wav audio file
问题描述
我必须在不使用任何外部 Python 库的情况下将 wav 文件从 44100Hz 下采样到 16000Hz,所以最好是 wave
和/或 audioop
.我尝试使用 setframerate
函数将 wav 文件的帧速率更改为 16000,但这只会减慢整个录制的速度.如何将音频文件下采样到 16kHz 并保持音频的相同长度?
I have to downsample a wav file from 44100Hz to 16000Hz without using any external Python libraries, so preferably wave
and/or audioop
. I tried just changing the wav files framerate to 16000 by using setframerate
function but that just slows down the entire recording. How can I just downsample the audio file to 16kHz and maintain the same length of the audio?
推荐答案
可以使用Librosa的load()函数,
You can use Librosa's load() function,
import librosa
y, s = librosa.load('test.wav', sr=8000) # Downsample 44.1kHz to 8kHz
安装 Librosa 的额外努力可能值得高枕无忧.
The extra effort to install Librosa is probably worth the peace of mind.
专业提示:在 Anaconda 上安装 Librosa 时,您还需要安装 ffmpeg,所以
Pro-tip: when installing Librosa on Anaconda, you need to install ffmpeg as well, so
pip install librosa
conda install -c conda-forge ffmpeg
这样可以避免 NoBackendError() 错误.
This saves you the NoBackendError() error.
这篇关于下采样 wav 音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!