使用ffmpeg sox或opus到file.txt获取每0.1秒音频文件的音频当前频率

问题描述 投票:0回答:1

我试图从file.opus中的调用记录获取音频频率统计每0.1秒,尝试ffmpeg(频谱)ffprobe,例如sox '.$file.' −n rate 6k spectrogram −z 62 -w Hamming -o aaaaaa/test10.png stat -freq 2>aaaaaa/test10.txt返回频谱所有返回值但没有频率找到任何其他库?或者我做错了我现在它重新开始频谱,但是我需要具体的人声,这可以用ffmpeg或ffprobe或sox吗?我在php工作,但运行shel命令任何帮助将是有意义的。我的下一步应该是什么?我迷路了我不知道怎么能从这个数字得到频率或“它是可能的”??? sox等的第一步命令是什么?

php ffmpeg frequency sox frequency-analysis
1个回答
0
投票

所以,我有我认为“不好”的解决方案,初学者在音频好文章女巫帮助我FFT for beginner然后研究SOX stats文档使用以下代码获取

  1. 粗糙的频率
$z = 0;
$timeFrom = 0;
$freqencies = array();
$fftPoints = 4098/2; 
//sox could give only 2048 freqencies spectrum
$file = 'myMp3Test.mp3';// 10 seconds
$interval = 1/8;//1/8 second 
//best results I got with this interval smaller gives as well zeros
//80 because 10 seconds interval 1/8 = 80 measurments
while($z <= 80){

    $outputexec = '';   

    exec('sox  '.$file.' −n trim '.$timeFrom.' '.$interval.' rate 1024 stat -freq  2>&1', $outputexec);

    $timeFrom = $timeFrom + $interval;

    $resultLength = (count($outputexec)-12) ;
  // - 12 means extra 12 rows in result with stats
    $cycles = $resultLength / $fftPoints ;

  $x = 1;
    while($x<=$cycles){

        $buffer = array();
        $till = $fftPoints*$x;

        $i = $till - $fftPoints;

        while($i < $till){
            $prA = explode("  ",$outputexec[$i]);
            if(isset($prA[1])){ $buffer[] = $prA[1]; }
            $i = $i + 1;
        }   

        $maxValue = max($buffer);

        $j = ($till>$fftPoints)? $till - $fftPoints: 0;

        while($j < $till){
            $prB = explode("  ",$outputexec[$j]);
            if(isset($prB[1])){
                if($prB[1] == $maxValue) { 
                     $freqencies[] = $prB[0];
                    break;
                }
            }           
            $j = $j + 1;
        }

        $x = $x + 1;
    }
    $z = $z+1;
}

//result is in freqencies arrray
  1. 平均音量
exec('ffmpeg -i "'.$file.'" -filter:a volumedetect  -f null /dev/null 2>&1', $outputrmsA );
foreach($outputrmsA as $vysledok){
    if(preg_match("/mean_volume/", $vysledok)){
        $vprenos = explode('mean_volume: ',$vysledok);
        $mean_volume = (trim(str_replace(" ", "",(str_replace(" dB", "",$vprenos[1])))));
    }
}
var_dump($mean_volume);
  1. Spectrum,png exec('sox '.$file.' −n rate 4096 spectrogram −z 60 -w Hamming -o aaaaaa/ORG.png');

我很乐意接受更正或更好的答案,对于我在个人mp3上测试它的任何建议而言,这是0,005容忍OK

© www.soinside.com 2019 - 2024. All rights reserved.