scipy.io.wavfile.read
은 .wav
파일을 헤더와 파일에 포함 된 데이터로 분해하는 편리한 래퍼입니다. 소스로부터 source code
Returns
-------
rate : int
Sample rate of wav file.
data : numpy array
Data read from wav file. Data-type is determined from the file;
see Notes.
단순화 코드 가입일
:
fid = open(filename, 'rb')
try:
file_size, is_big_endian = _read_riff_chunk(fid) # find out how to read the file
channels = 1 # assume 1 channel and 8 bit depth if there is no format chunk
bit_depth = 8
while fid.tell() < file_size: #read the file a couple of bytes at a time
# read the next chunk
chunk_id = fid.read(4)
if chunk_id == b'fmt ': # retrieve formatting information
fmt_chunk = _read_fmt_chunk(fid, is_big_endian)
format_tag, channels, fs = fmt_chunk[1:4]
bit_depth = fmt_chunk[6]
if bit_depth not in (8, 16, 32, 64, 96, 128):
raise ValueError("Unsupported bit depth: the wav file "
"has {}-bit data.".format(bit_depth))
elif chunk_id == b'data':
data = _read_data_chunk(fid, format_tag, channels, bit_depth,is_big_endian, mmap)
finally:
if not hasattr(filename, 'read'):
fid.close()
else:
fid.seek(0)
return fs, data
데이터 자체는 PCM은 상이한 채널에 대한 연속적인 프레임에서의 음압 레벨을 나타내는 일반적이다. scipy.io.wavfile.read
에 의해 반환되는 샘플링 속도는 초를 나타내는 프레임 수를 결정하는 데 필요합니다.
.wav
형식에 대한 설명은 question입니다.
scipy는 독자적으로 많이 계산하지 않습니다.