gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 05:20:50 25 4
gpt4 key购买 nike

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

谁能通俗地告诉我这些数据是如何准备的?

附言。我在某处读到它意味着振幅?我读的是正确的吗?如果是,scipy.io.wavfile.read 是如何计算和返回振幅的?

最佳答案

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 表示的不同 channel 的连续帧中的声压级。 scipy.io.wavfile.read 返回的采样率对于确定多少帧代表一秒是必要的。

question 提供了.wav 格式的一个很好的解释。 .

scipy 本身计算不多。

关于python - scipy.io.wavfile.read 返回的数据是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40399930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com