其他分享
首页 > 其他分享> > PCM 转WAV

PCM 转WAV

作者:互联网

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)
        

标签:output,name,filepath,PCM,wav,filename,import,WAV
来源: https://blog.csdn.net/funkidd/article/details/122215802