下采样WAV音频文件 [英] Downsampling wav audio file

查看:147
本文介绍了下采样WAV音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在不使用任何外部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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆