在给定时间获取声音文件中的振幅? [英] Get the amplitude at a given time within a sound file?

查看:141
本文介绍了在给定时间获取声音文件中的振幅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个项目,在该项目中,我需要知道计算机上麦克风传来的声音振幅.

我目前正在将Python与 Snack Sound Toolkit 一起使用,并且可以录制音频从麦克风传来的声音,但我需要知道音频的音量.我可以将录音保存到文件中,并使用另一个工具包从音频文件中的给定时间点读取幅度,或者尝试在音频进入时获取幅度(这更容易出错).

是否有任何库或示例代码可以帮助我解决这个问题?我一直在寻找,到目前为止,Snack Sound Toolkit似乎是我最大的希望,但似乎还没有办法直接获得振幅.

解决方案

在Snack Sound Toolkit示例中,似乎有一个dbPowerSpectrum函数.

从参考文献:

dBPowerSpectrum()

计算声音的对数FFT功率谱(以开始选项中给出的样本数),并返回dB值列表.有关其余选项的说明,请参见本节.可选地,可以使用end选项指定终点.在这种情况下,结果是指定范围内连续FFT的平均值.它们的默认间隔是从fftlength中获取的,但是可以使用skip选项更改该间隔,该选项可告诉您每步移动FFT窗口多少个点.选项:

我假设当您说振幅时,是指声音对人的感觉是大声",而不是时域电压(由于正弦波的积分将在整个长度上变为0,设为0.例如:10 * sin(t)大于5 * sin(t),但它们随时间的平均值为0.(无论如何,您都不希望向扬声器发送非AC电压).

要获取声音的声音,您需要确定每个频率分量的幅度.这是通过傅立叶变换(FFT)来完成的,它可以将声音分解为频率分量. dbPowerSpectrum函数似乎为您提供了每个频率的幅度列表(如果与功率谱的确切定义不同,请原谅).要获得总音量,您可以将整个列表加起来(这很接近,因为人耳本身具有频率响应,所以它可能与感知的响度有所不同).

I'm working on a project where I need to know the amplitude of sound coming in from a microphone on a computer.

I'm currently using Python with the Snack Sound Toolkit and I can record audio coming in from the microphone, but I need to know how loud that audio is. I could save the recording to a file and use another toolkit to read in the amplitude at given points in time from the audio file, or try and get the amplitude while the audio is coming in (which could be more error prone).

Are there any libraries or sample code that can help me out with this? I've been looking and so far the Snack Sound Toolkit seems to be my best hope, yet there doesn't seem to be a way to get direct access to amplitude.

解决方案

Looking at the Snack Sound Toolkit examples, there seems to be a dbPowerSpectrum function.

From the reference:

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:

EDIT: I am assuming when you say amplitude, you mean how "loud" the sound appears to a human, and not the time domain voltage(Which would probably be 0 throughout the entire length since the integral of sine waves is going to be 0. eg: 10 * sin(t) is louder than 5 * sin(t), but their average value over time is 0. (You do not want to send non-AC voltages to a speaker anyways)).

To get how loud the sound is, you will need to determine the amplitudes of each frequency component. This is done with a Fourier Transform (FFT), which breaks down the sound into it's frequency components. The dbPowerSpectrum function seems to give you a list of the magnitudes (forgive me if this differs from the exact definition of a power spectrum) of each frequency. To get the total volume, you can just sum the entire list (Which will be close, xept it still might be different from percieved loudness since the human ear has a frequency response itself).

这篇关于在给定时间获取声音文件中的振幅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆