0

i ran into some problems lately with SoX and PHP. I am a complete beginner in running command-line tools in PHP, so i try to describe the problem as good as i can:

So we have the following situation:

There is a .wav-file in the folder [root]/demo/test.wav

My php-file is located is located in [root]/inc/classes.php

So the php looks somewhat like this (really a minimal example)

function wav() {
    $output = shell_exec('sox ..\demo\test.wav -n stat');
    var_dump($output);
    echo "<pre>".$output."</pre>";
}

So if i run the function (and if i take a really huge .wav-file) it seems to "do" something, because the browser takes a long time to run the request.

But everything i receive is "NULL"

If i change the shell_exec-command to shell_exec('sox -help') it works.

So my question is: How come? xD

best regards

bquarta
  • 559
  • 6
  • 19

1 Answers1

1

I've been banging my head against the wall with this one too. You were the only documented problem I could find on it. All I wanted was the mp3 duration.

shell_exec("sox test.mp3 -n stat") // was returning NULL

but

shell_exec("sox --i -D test.mp3") // worked!

No idea why.

Three months late, but this might save someone some time.

user2224693
  • 122
  • 7
  • Hehe, thank you. I found the solution myself after a while and honestly completely forgot about this post :D... The problem "seems" to me that what sox returns is not always in the same format. Some things come as an array, some as a single value. I believe _-n -stat_ gives you an array of values while _--i -D_ just gives you a single value. – bquarta Jun 20 '14 at 08:59