import wave
import os
import wave
import numpy as np
def gen_wav(filepath):
wavelist=[]
filenames=os.listdir(filepath)
for filename in filenames:
print(filename)
name,category=os.path.splitext(filepath+filename) #分解文件扩展名
# name,category=os.path.splitext(filename) #分解文件扩展名
if category=='.pcm': #若文件为wav音频文件
print(name+'.wav')
with open(filepath+filename, 'rb') as pcmfile:
pcmdata = pcmfile.read()
output = wave.open(name+'.wav', 'wb')
output.setparams((1, 2, 32000, 0, 'NONE', 'NONE'))
output.writeframes(pcmdata)
output.close()
filepath="/Users/anker/Documents/2_Speech_data/anker设备实际录音/3382/Stage1/Katar/键盘 1hour/"
gen_wav(filepath)