본문 바로가기
Algorithm

[Audio] WAVE - PCM 변환하기

by 공대우냉이 2021. 12. 22.

상황: wav 파일을 PCM으로 읽기

Method 1) 

with open(file_path, 'rb') as f:

    file_data = bytearray(file.read())

pcm_data = file_data[44:]

- bytearray는 써도 되고, 안써도 됨. (아직까진 같은 결과...)

 

Method 2)

import wave

with contextlib.closing(wave.open(file_path, 'rb')) as wf:

    pcm_data = wf.readframes(wf.getnframes())

    sample_rate = wf.getframerate()