#!/usr/bin/env python
import numpy as np
import wave
import math
import ctypes as ct
class FloatBits(ct.Structure):
_fields_ = [
('M', ct.c_uint, 23),
('E', ct.c_uint, 8),
('S', ct.c_uint, 1)
]
class Float(ct.Union):
_anonymous_ = ('bits',)
_fields_ = [
('value', ct.c_float),
('bits', FloatBits)
]
def nextpow2(x):
if x < 0:
x = -x
if x == 0:
return 0
d = Float()
d.value = x
if d.M == 0:
return d.E - 127
return d.E - 127 + 1
# 打开WAV文档
f = wave.open("test.wav")
# 读取格式信息
# (nchannels, sampwidth, framerate, nframes, comptype, compname)
params = f.getparams()
nchannels, sampwidth, framerate, nframes = params[:4]
fs = framerate
# 读取波形数据
str_data = f.readframes(nframes)
f.close()
# 将波形数据转换为数组
x = np.fromstr
谱减法降噪(python实现)
最新推荐文章于 2023-09-05 21:15:00 发布