wav文件音频采集频率44.1k降为8k

wav文件音频采集频率44.1k降为8k

import wave
import struct
def save_wave_file(filename, data):
    wf1 = wave.open(filename, 'wb')
    wf1.setnchannels(1)
    wf1.setsampwidth(2)# 2byte 16bit
    wf1.setframerate(8000)
    wf1.writeframes(b"".join(data))
    wf1.close()

wf = wave.open(r"109.wav", "rb")
b=[]
print(type(b),wf.getnchannels(),wf.getframerate(), wf.getnframes(),wf.getframerate(),wf.getsampwidth())
print(wf.getnframes())
for x in range(0,wf.getnframes()//3000):
    str_data = wf.readframes(3000)
    for a in range(0,500):
        b.append(str_data[24*a:24*a+2])
save_wave_file("109_44k_to_8k.wav",b)
wf.close()

你可能感兴趣的:(语音处理,wav,44.1k转8k,python)