如何检测浮点音频文件

How to detect a floating point audio file

我正在使用 pydub 检查 bit_depth 和音频文件(wav 和 flacc)的帧速率。我如何验证它是否为浮点数?

https://en.wikipedia.org/wiki/Audio_bit_depth#Floating_point

我试图从 pydub 检查 sample_rate 的类型,但它总是 int

采样率位于音频文件的 X 轴上。它始终是 int,值从 11025 变为 22050 或 44100 Hz。

您正在查找音频文件的位深度。较旧的音乐有 8 位。 CD 有 16 位。浮点数为 32 位。乍一看,不可能区分 32 位整数和 32 位浮点数。

不过,这个信息是在fmt部分给出的,至少有一个RIFF WAV file. The German Wikipedia has a list of file formats (here)。 0x0003 IEEE FLOAT 应该是你要找的。

在 pydub 中,这会为您提供格式信息:

from pydub.utils import mediainfo_json

info = mediainfo_json('example.wav')
audio_streams = [x for x in info['streams'] if x['codec_type'] == 'audio']
print(audio_streams[0].get('sample_fmt'))

使用具有 32 位浮点数的示例文件,我得到 flt 作为输出。您的里程可能会有所不同。