如何从原始数组数据评估声音片段的持续时间?
我从麦克风获取原始数据,并且知道采样率和通道数。我需要数学公式来计算此音频片段的持续时间。
我发现了这一点:
1000 * bytesLength / 4 / rate_hz
但我认为这是错误的。
平衡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
此公式表示上述变量之间的关系:
storage_in_bytes / second == num_channels * sample_rate * bit_depth / 8
数秒求解:(这是您要求的方程式)
duration in seconds = storage_in_bytes/(num_channels * sample_rate * (bit_depth/8))
使用上述变量插入时,我们需要提供storage_in_bytes或持续时间(以秒为单位),因此如果
storage_in_bytes = 2 mb = 2097152 bytes
然后我们得到
duration = 2097152/(2 * 44100 * (16/8)) = 11.89 seconds
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句