python 读取wav的采样率

March 1, 2020, 10:28 a.m.

read: 1680

使用标准库读取

# librosa
import librosa
y, sr = librosa(filename, sr=None)。

# pysoundfile
import soundfile as sf
sig, sr = sf.read(filename)

# scipy
from scipy.io import wavfile
sr, sig = wavfile.read(filename)

考虑效率的话直接读取文件头

# 直接读取二进制流
# 从上图可以看到读取24-28字节的数据就是其采样率
import struct
def read_sample_rate(filename):
    '''
    在标准44字节头上测试可用 在au等软件生成的非标准头上尚未测试,请等待更新
    '''
    with open(filename, 'rb') as wav_file:
        a = wav_file.read(28)
        sr = struct.unpack('i', a[24:28])[0]
    return sr

print(read_sample_rate('1.wav'))




音频信号的三次样条插值学习笔记

对音频信号进行三次样条插值(Cubic Spline Interpolation)以8k插值为16k信号为例,下方为matlab代码 [y, fs] = audioread('8k.wav'); …

使用ffmpeg对wav文件进行降采样

文章标题:使用ffmpeg对wav文件进行降采样文章内容:依赖pysoundfile,ffmpeg把采样率大于16k的wav文件降采样为16k速度比使用librosa快很多,适合批量处理的情况不适合…

此站点由 ASP.NETIIS 驱动 | © 2018-2023 hupeng.me. All Rights Reserved.