修改WAV头
April 19, 2018, 9:50 p.m.
read: 979
WAV头文
16kHz的情况
波形音频数据传送速率,其值为通道数×每秒数据位数×每样本的数据位数/8
1 * 16000 * 16 / 8 = 32000
修改到正确的值
def modify_wav(wav_file_path):
with open(wav_file_path, 'rb+') as wav_file:
with open(wav_file_path.replace(".wav", "") + "_modify.wav", "wb+") as new_wav_file:
index = 0
while True:
data = wav_file.read(1)
if not data:
break
if index == 28 or index == 29:
if index == 28:
new_wav_file.write(b'\x00')
if index == 29:
new_wav_file.write(b'}')
else:
new_wav_file.write(data)
index += 1
简单方法:
import soundfile as sf
sig, sr = sf.read(wav_file_path)
sf.write(wav_file_path, sig, sr)