简体   繁体   English

从声音片段的原始音频阵列数据评估持续时间

[英]Evaluate duration from raw audio array data of sound fragment

How to evaluate duration of sound fragment from raw array data? 如何从原始数组数据评估声音片段的持续时间?

I get raw data from microphone and I know the sample rate and the number of channels. 我从麦克风获取原始数据,并且知道采样率和通道数。 I need mathematical formula to calculate the duration of this audio fragment. 我需要数学公式来计算此音频片段的持续时间。

I found out this: 我发现了这一点:

1000 * bytesLength / 4 / rate_hz

But I think it's wrong. 但我认为这是错误的。

Salient factors balancing off quality against resource demands for raw audio in PCM format : 平衡PCM格式原始音频的质量和资源需求之间的突出因素:

 Attribute     Typical Values
____________  _________________
bit_depth     16 bits per sample (8 bits per byte)        ... higher the better
num_channels  2 for stereo (or 1 for mono), lets use stereo
sample_rate   44100 samples per second (CD quality audio) ... higher the better

This formula expresses relationship between above variables : 此公式表示上述变量之间的关系:

storage_in_bytes / second == num_channels * sample_rate * bit_depth / 8

solving for seconds : (here is the equation you ask for) 数秒求解:(这是您要求的方程式)

duration in seconds = storage_in_bytes/(num_channels * sample_rate * (bit_depth/8))

plugging in using above variables we need to supply either storage_in_bytes or duration in seconds, so if 使用上述变量插入时,我们需要提供storage_in_bytes或持续时间(以秒为单位),因此如果

storage_in_bytes = 2 mb = 2097152 bytes

then we get 然后我们得到

duration = 2097152/(2 * 44100 * (16/8)) = 11.89 seconds

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM