1. 程式人生 > >Python PCM轉WAV

Python PCM轉WAV

下面給出一個16K單通道的pcm轉wav的樣例

import wave
pcm_path = r'1537176475276.pcm'

with open(pcm_path, 'rb') as pcmfile:
    pcmdata = pcmfile.read()
with wave.open(pcm_path + '.wav', 'wb') as wavfile:
    wavfile.setparams((1, 2, 16000, 0, 'NONE', 'NONE'))
    wavfile.writeframes(pcmdata)

wavfile.setparams的引數說明如下:
聲道數, 量化位數(byte單位), 取樣頻率,取樣點數, 壓縮型別, 壓縮型別的描述。wave模組只支援非壓縮的資料,因此可以忽略最後兩個資訊