[英]Evaluate duration from raw audio array data of sound fragment
如何從原始數組數據評估聲音片段的持續時間?
我從麥克風獲取原始數據,並且知道采樣率和通道數。 我需要數學公式來計算此音頻片段的持續時間。
我發現了這一點:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.