scipy.io.wavfile.read返回的数据是什么意思?

时间:2016-11-03 11:06:11

标签: python scipy wav

scipy.io.wavfile.read的文档说它返回采样率和数据。但是,.wav文件的数据实际上意味着什么?

任何人都可以通过外行的方式让我知道如何准备这些数据?

PS。我读到某处意味着振幅?我读的是正确的吗?如果是,那么scipy.io.wavfile.read

计算和返回的幅度如何?

1 个答案:

答案 0 :(得分:0)

scipy.io.wavfile.read是一个便利包装器,用于将.wav文件分解为标头和文件中包含的数据。

来自https://groups.google.com/forum/#!msg/jacoco/8zjkSseaxD4/QOux-Ws-AgAJ

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返回的采样率对于确定表示秒数的帧数是必要的。

source code提供了.wav格式的详细说明。

scipy并不能自行计算。