参考资料:
https://zh.wikipedia.org/wiki/WAV
http://soundfile.sapp.org/doc/WaveFormat/
https://stackoverflow.com/questions/56949033/wav-and-mp3-file-duration-with-php
<?php | |
// 简单版本 | |
$filename = 'LoveMe.wav'; | |
$wavdataoffset = 44; | |
$wavdataend = filesize($filename); | |
$fp = fopen($filename, 'rb'); | |
$fseek = fseek($fp, 28); | |
$bitrate = unpack('V', fread($fp, 4)); | |
$bitrate = $bitrate[1]; | |
$playtime_seconds = (float)(($wavdataend - $wavdataoffset) / $bitrate); | |
fclose($fp); | |
$playtime_string = playtimeString($playtime_seconds); | |
// 可以考虑四舍五入 | |
$playtime_seconds = (int)ceil($playtime_seconds); | |
echo "秒数:${playtime_seconds}秒\n时长:${playtime_string}\n"; |