如何从原始数组数据中评估声音片段的持续时间?
我从麦克风获取原始数据,并且知道采样率和 channel 数。我需要数学公式来计算这个音频片段的持续时间。
我发现了这个:
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
关于javascript - 从声音片段的原始音频数组数据评估持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34476299/