Get length of .wav from sox output

2019-03-14 06:29发布

I need to get the length of a .wav file.

Using:

sox output.wav -n stat

Gives:

Samples read:            449718
Length (seconds):     28.107375
Scaled by:         2147483647.0
Maximum amplitude:     0.999969
Minimum amplitude:    -0.999969
Midline amplitude:     0.000000
Mean    norm:          0.145530
Mean    amplitude:     0.000291
RMS     amplitude:     0.249847
Maximum delta:         1.316925
Minimum delta:         0.000000
Mean    delta:         0.033336
RMS     delta:         0.064767
Rough   frequency:          660
Volume adjustment:        1.000

How do I use grep or some other method to only output the value of the length in the second column, i.e. 28.107375?

Thanks

9条回答
Anthone
2楼-- · 2019-03-14 07:22

There is a better way:

soxi -D out.wav
查看更多
狗以群分
3楼-- · 2019-03-14 07:22

for ruby:

string = `sox --i -D file_wav 2>&1` 
string.strip.to_f
查看更多
Fickle 薄情
4楼-- · 2019-03-14 07:22

sox stat output to array and json encode

        $stats_raw = array();
        exec('sox file.wav -n stat 2>&1', $stats_raw);
        $stats = array();

        foreach($stats_raw as $stat) {
            $word = explode(':', $stat);
            $stats[] = array('name' => trim($word[0]), 'value' => trim($word[1]));
        } 
        echo json_encode($stats);
查看更多
登录 后发表回答