我正在做一个项目,我需要知道从计算机上的麦克风传来的声音的振幅。
我目前正在使用 Python 和 Snack Sound Toolkit我可以录制来自麦克风的音频,但我需要知道该音频的音量。我可以将录音保存到一个文件中,然后使用另一个工具包从音频文件中读取给定时间点的振幅,或者尝试在音频进入时获取振幅(这可能更容易出错)。
是否有任何库或示例代码可以帮助我解决这个问题?我一直在寻找,到目前为止 Snack Sound Toolkit 似乎是我最大的希望,但似乎没有办法直接访问振幅。
请您参考如下方法:
查看 Snack Sound Toolkit 示例,似乎有一个 dbPowerSpectrum 函数。
来自引用:
dBPowerSpectrum ( )
Computes the log FFT power spectrum of the sound (at the sample number given in the start option) and returns a list of dB values. See the section item for a description of the rest of the options. Optionally an ending point can be given, using the end option. In this case the result is the average of consecutive FFTs in the specified range. Their default spacing is taken from the fftlength but this can be changed using the skip option, which tells how many points to move the FFT window each step. Options:
编辑:我假设当你说振幅时,你的意思是声音对人来说有多“响亮”,而不是时域电压(由于正弦波的积分正在发生,在整个长度上可能为 0为 0。例如:10 * sin(t) 比 5 * sin(t) 大,但它们随时间的平均值为 0。(无论如何,您不想向扬声器发送非交流电压)。
要了解声音的大小,您需要确定每个频率分量的振幅。这是通过傅里叶变换 (FFT) 完成的,它将声音分解成它的频率分量。 dbPowerSpectrum 函数似乎为您提供了每个频率的幅度列表(如果这与功率谱的确切定义不同,请原谅)。要获得总音量,您可以将整个列表相加(这将很接近,但它仍然可能与感知响度不同,因为人耳本身具有频率响应)。
