Save Sox output stats info with shell_exe

I'm driving crazy with this. I use sox to convert files, trim them, apply some effects, etc.

I'm using php scripts to call the program and it works ok except when I try to retrieve the output info, for example to get the stats of the file and save it in a variable:

<?php
exec("/usr/bin/sox uploads/jingle.wav -n stat", $outputrms);
                var_dump($outputrms);
?>

//also tried

<?php
$outputrms = shell_exec("/usr/bin/sox uploads/jingle.wav -n stats");
                var_dump($outputrms);
?>

Always getting NULL response or empty array. If I go to the command line it works just perfect showing:

             Overall     Left      Right
DC offset   0.003469  0.003469  0.003469
Min level  -0.971375 -0.971375 -0.971313
Max level   0.999969  0.999969  0.999969
Pk lev dB      -0.00     -0.00     -0.00
RMS lev dB    -14.37    -14.37    -14.37
RMS Pk dB      -5.94     -5.94     -5.94
RMS Tr dB     -66.86    -66.86    -66.86
Crest factor       -      5.23      5.23
Flat factor     0.00      0.00      0.00
Pk count           7         7         7
Bit-depth      16/16     16/16     16/16
Num samples     136k
Length s       3.082
Scale max   1.000000
Window s       0.050

What I'm I doing wrong?

Regards

Upvotes: 0

Views: 924

Answers (2)

Tars
Tars

Reputation: 99

exec('sox assets/test.mp3 -n stat 2>&1', $output);
print_r($output);

Use 2>&1 is okey, And I don't know why...

Upvotes: 0

It seems sox was sending the output as a warning output and not standard output. I just added 2>&1 at the end of the code and that solved it.

<?php
exec("/usr/bin/sox uploads/jingle.wav -n stat", $outputrms 2>&1);
                var_dump($outputrms);
?>

Upvotes: 1

Related Questions