Martin Kucej | 17 Aug 07:20 2010
Picon

Execute PHP from Sox

Hi:

I have tried to execute Sox from PHP with exec and such. On Windows XP, 
everything seems to work. On Ubuntu 10.04 converting works, however, playing and 
recording does not work, because the default ALSA device throws errors. The same 
command (sox song.ogg -d) works fine in the console. One obvious difference is 
that PHP runs as a different user "www-data" and I have read somewhere that ALSA 
has problems with this. The error message is below. Do you think this can be 
made to work somehow, or I just need to forget it?

Home directory /var/www not ours.
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4154:(_snd_config_evaluate) function snd_func_card_driver 
returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4154:(_snd_config_evaluate) function snd_func_concat returned 
error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4154:(_snd_config_evaluate) function snd_func_refer returned 
error: No such file or directory
ALSA lib conf.c:4633:(snd_config_expand) Evaluate error: No such file or 
directory
ALSA lib pcm.c:2211:(snd_pcm_open_noupdate) Unknown PCM default
sox FAIL formats: can't open output file `default': snd_pcm_open error: No such 
file or directory

Thanks,
Martin

------------------------------------------------------------------------------
(Continue reading)

Pascal Giard | 17 Aug 15:33 2010
Picon

Re: Execute PHP from Sox

On Tue, Aug 17, 2010 at 1:20 AM, Martin Kucej <mkucej <at> yahoo.com> wrote:
> Hi:
>
> I have tried to execute Sox from PHP with exec and such. On Windows XP,
> everything seems to work. On Ubuntu 10.04 converting works, however, playing and
> recording does not work, because the default ALSA device throws errors. The same
> command (sox song.ogg -d) works fine in the console. One obvious difference is
> that PHP runs as a different user "www-data" and I have read somewhere that ALSA
> has problems with this. The error message is below. Do you think this can be
> made to work somehow, or I just need to forget it?
>
> Home directory /var/www not ours.
> ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
> ALSA lib conf.c:4154:(_snd_config_evaluate) function snd_func_card_driver
> returned error: No such file or directory
> ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
> ALSA lib conf.c:4154:(_snd_config_evaluate) function snd_func_concat returned
> error: No such file or directory
> ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
> ALSA lib conf.c:4154:(_snd_config_evaluate) function snd_func_refer returned
> error: No such file or directory
> ALSA lib conf.c:4633:(snd_config_expand) Evaluate error: No such file or
> directory
> ALSA lib pcm.c:2211:(snd_pcm_open_noupdate) Unknown PCM default
> sox FAIL formats: can't open output file `default': snd_pcm_open error: No such
> file or directory
>
> Thanks,
> Martin

(Continue reading)

Martin Kucej | 18 Aug 04:22 2010
Picon

Re: Execute PHP from Sox

> Hi Martin,

>  first thing that comes to mind, what if you add  www-data to the audio group?

Thanks for the idea, Pascal. It did not make any difference though.
Martin

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
Pascal Giard | 18 Aug 16:57 2010
Picon

Re: Execute PHP from Sox

On Tue, Aug 17, 2010 at 10:22 PM, Martin Kucej <mkucej <at> yahoo.com> wrote:
>> Hi Martin,
>
>>  first thing that comes to mind, what if you add  www-data to the audio group?
>
> Thanks for the idea, Pascal. It did not make any difference though.
> Martin

Hi Martin,
 i believe you simply forgot to restart your apache server after
adding www-data to the audio group.

I just installed apache2 and php5 to test it myself.
Out of the box, it did not work.

I added www-data to audio.
It did not work.

I restarted apache (/etc/init.d/apache2 restart).
It worked!

Here's my very simple sox.php script:
<?php
	echo "OMG SoX plays a song thru Apache/PHP!";
	passthru("/usr/bin/play /tmp/test.mp3");
?>

Cheers,

-Pascal
(Continue reading)

Pascal Giard | 18 Aug 17:03 2010
Picon

Re: Execute PHP from Sox

On Wed, Aug 18, 2010 at 10:57 AM, Pascal Giard <evilynux <at> gmail.com> wrote:
> On Tue, Aug 17, 2010 at 10:22 PM, Martin Kucej <mkucej <at> yahoo.com> wrote:
>>> Hi Martin,
>>
>>>  first thing that comes to mind, what if you add  www-data to the audio group?
>>
>> Thanks for the idea, Pascal. It did not make any difference though.
>> Martin
>
> Hi Martin,
>  i believe you simply forgot to restart your apache server after
> adding www-data to the audio group.
>
> I just installed apache2 and php5 to test it myself.
> Out of the box, it did not work.
>
> I added www-data to audio.
> It did not work.
>
> I restarted apache (/etc/init.d/apache2 restart).
> It worked!
>
> Here's my very simple sox.php script:
> <?php
>        echo "OMG SoX plays a song thru Apache/PHP!";
>        passthru("/usr/bin/play /tmp/test.mp3");
> ?>

On a sidenote, as i've used sox's default verbosity level and play
outputs on stderr, i get the info in /var/log/apache2/error.log.
(Continue reading)

Chris Bagwell | 18 Aug 18:19 2010

Re: Execute PHP from Sox

On Wed, Aug 18, 2010 at 10:03 AM, Pascal Giard <evilynux <at> gmail.com> wrote:
> On a sidenote, as i've used sox's default verbosity level and play
> outputs on stderr, i get the info in /var/log/apache2/error.log.
>
> Looks like this...
> `tail -n 10 /var/log/apache2/error.log`
> /tmp/test.mp3:
>
>  File Size: 6.00M     Bit Rate: 199k
>  Encoding: MPEG audio    Info: 2006
>  Channels: 2  <at>  16-bit   Track: 1/12
> Samplerate: 44100Hz      Album: Parasited Evolution
> Replaygain: off         Artist: Luen-Ta
>  Duration: 00:04:00.90  Title: Undeads
>
> In:100%  00:04:00.90 [00:00:00.00] Out:11.6M [      |      ]
>
> All that to say that you may want to change the verbosity level to 1 or 2.
>

The "-q" option will help here I think.

That brings up a good point though.  The progress is displayed when it
detects an audio device.

SoX sets an internal flag called stdin_is_a_tty that could be looked
at and disable progress by default like we are doing for interactive
support.  I kinda thought it was doing that at one point.

Chris
(Continue reading)

Pascal Giard | 18 Aug 18:27 2010
Picon

Re: Execute PHP from Sox

On Wed, Aug 18, 2010 at 12:19 PM, Chris Bagwell <chris <at> cnpbagwell.com> wrote:
> On Wed, Aug 18, 2010 at 10:03 AM, Pascal Giard <evilynux <at> gmail.com> wrote:
>> On a sidenote, as i've used sox's default verbosity level and play
>> outputs on stderr, i get the info in /var/log/apache2/error.log.
>>
>> Looks like this...
>> `tail -n 10 /var/log/apache2/error.log`
>> /tmp/test.mp3:
>>
>>  File Size: 6.00M     Bit Rate: 199k
>>  Encoding: MPEG audio    Info: 2006
>>  Channels: 2  <at>  16-bit   Track: 1/12
>> Samplerate: 44100Hz      Album: Parasited Evolution
>> Replaygain: off         Artist: Luen-Ta
>>  Duration: 00:04:00.90  Title: Undeads
>>
>> In:100%  00:04:00.90 [00:00:00.00] Out:11.6M [      |      ]
>>
>> All that to say that you may want to change the verbosity level to 1 or 2.
>>
>
> The "-q" option will help here I think.

Indeed, that's more appropriate as -V1 or -V2 won't make the progress
go away in this very example.

> That brings up a good point though.  The progress is displayed when it
> detects an audio device.
>
> SoX sets an internal flag called stdin_is_a_tty that could be looked
(Continue reading)

Martin Kucej | 18 Aug 19:51 2010
Picon

Re: Execute PHP from Sox

> Hi Martin,

>  i  believe you simply forgot to restart your apache server after
> adding www-data  to the audio group.

Hi Pascal:

You are correct. Adding www-data to the audio group and restarting Apache is all 
it takes for PHP to be able to execute Sox with access to ALSA. Great advice! 
The functionality of this combo is limited to localhost, but it will enable me 
to quickly build a simple web GUI for Sox and integrate it into my web-based 
application. Thank you.

Best regards,
Martin

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
Pascal Giard | 18 Aug 20:07 2010
Picon

Re: Execute PHP from Sox

On Wed, Aug 18, 2010 at 1:51 PM, Martin Kucej <mkucej <at> yahoo.com> wrote:
>> Hi Martin,
>
>>  i  believe you simply forgot to restart your apache server after
>> adding www-data  to the audio group.
>
>
> Hi Pascal:
>
> You are correct. Adding www-data to the audio group and restarting Apache is all
> it takes for PHP to be able to execute Sox with access to ALSA. Great advice!
> The functionality of this combo is limited to localhost, but it will enable me
> to quickly build a simple web GUI for Sox and integrate it into my web-based
> application. Thank you.

Hi Martin,
 I'm happy I've helped you.
Now, you made me curious. What do you mean by "the functionality of
this combo is limited to localhost"?
Visiting the page from another host should also work. At least I don't
see why it wouldn't.

However, if you mean that it only plays/records on localhost, well for sure!
SoX is installed server-side. Thus, by definition it can only
record/play through the hardware available to the server.
(Ok, there may be some tricks you could use to broaden it's scope, but
not without pain (recording a streamed audio track from another server
comes to mind)).

In any case, if you want us to help you, it'd be nice to have an idea
(Continue reading)

Martin Kucej | 18 Aug 20:28 2010
Picon

Re: Execute PHP from Sox

> Now, you made me curious. What do you mean by "the functionality  of
> this combo is limited to localhost"?
> Visiting the page from another  host should also work. At least I don't
> see why it wouldn't.
> However,  if you mean that it only plays/records on localhost, well for sure!
> SoX is  installed server-side. Thus, by definition it can only
> record/play through  the hardware available to the server.
> (Ok, there may be some tricks you could  use to broaden it's scope, but
> not without pain (recording a streamed audio  track from another server
> comes to mind)).
> 
> In any case, if you want us  to help you, it'd be nice to have an idea
> of what you are trying to  achieve.

Yes, I meant that it can only record audio from the hardware on the server and 
not on a client. Therefore, enabling access remotely would not only be useless, 
but possibly even criminal. :-) As for the client side recording, I am curious 
what the new HTML5 device and media streaming functions will bring to the table.

I am not a programmer. I only do PHP web programming as a hobby. I wrote a PDF 
manager for students and scientists. I built in a note taking functionality, and 
then I realized that a lot of my colleagues, especially physicians, like to 
dictate their notes to a recorder. When I found Sox, I realized I could 
intergrate this directly into the PDF manager and create a voice recorder. I 
think that would be a first. :-) So far it looks like it might work.

Martin

------------------------------------------------------------------------------
This SF.net email is sponsored by 
(Continue reading)

Pascal Giard | 19 Aug 16:22 2010
Picon

Re: Execute PHP from Sox

On Wed, Aug 18, 2010 at 2:28 PM, Martin Kucej <mkucej <at> yahoo.com> wrote:
>> Now, you made me curious. What do you mean by "the functionality  of
>> this combo is limited to localhost"?
>> Visiting the page from another  host should also work. At least I don't
>> see why it wouldn't.
>> However,  if you mean that it only plays/records on localhost, well for sure!
>> SoX is  installed server-side. Thus, by definition it can only
>> record/play through  the hardware available to the server.
>> (Ok, there may be some tricks you could  use to broaden it's scope, but
>> not without pain (recording a streamed audio  track from another server
>> comes to mind)).
>>
>> In any case, if you want us  to help you, it'd be nice to have an idea
>> of what you are trying to  achieve.
>
> Yes, I meant that it can only record audio from the hardware on the server and
> not on a client. Therefore, enabling access remotely would not only be useless,
> but possibly even criminal. :-) As for the client side recording, I am curious
> what the new HTML5 device and media streaming functions will bring to the table.

Unfortunately, It's been a looong time since I've made development for the web.
That being said, a quick search on google reveals that lots of
developers are looking for that functionality (client side audio
recording).

> I am not a programmer. I only do PHP web programming as a hobby. I wrote a PDF
> manager for students and scientists. I built in a note taking functionality, and
> then I realized that a lot of my colleagues, especially physicians, like to
> dictate their notes to a recorder. When I found Sox, I realized I could
> intergrate this directly into the PDF manager and create a voice recorder. I
(Continue reading)

Martin Kucej | 19 Aug 17:12 2010
Picon

Re: Execute PHP from Sox

> Even if users are "forced" to have a webserver running on  their

> machine, that sounds like a very useful application.
> I happen to be  a research professional and a Ph.D. candidate, that's
> something that could be  useful.
> Is your application free/libre? ;-)

Actually, Apache and PHP take up negligible amount of resources (for small 
amount of users). Also, if the access is restricted to localhost it is is safe. 
The application is licensed under GPLv3:
http://www.bioinformatics.org/librarian
It is heavily skewed towards biomedicine though. Anyway, this conversation is 
probably outside the scope of this list. I am happy to answer your further 
questions privately.
Best regards,
Martin

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
Fmiser | 19 Aug 21:54 2010
Picon

Re: Execute PHP from Sox

> Martin Kucej wrote:

> Anyway, this conversation is probably outside the scope of
> this list.

Well, it may be outside the literal scope - but I'm following along. :)

--     Philip

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
Chris Bagwell | 17 Aug 15:35 2010

Re: Execute PHP from Sox


On Aug 17, 2010, at 12:20 AM, Martin Kucej <mkucej <at> yahoo.com> wrote:

> Hi:
> 
> I have tried to execute Sox from PHP with exec and such. On Windows XP, 
> everything seems to work. On Ubuntu 10.04 converting works, however, playing and 
> recording does not work, because the default ALSA device throws errors. The same 
> command (sox song.ogg -d) works fine in the console. One obvious difference is 
> that PHP runs as a different user "www-data" and I have read somewhere that ALSA 
> has problems with this. The error message is below. Do you think this can be 
> made to work somehow, or I just need to forget it?
> 
> Home directory /var/www not ours.
> ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
> ALSA lib conf.c:4154:(_snd_config_evaluate) function snd_func_card_driver 
> returned error: No such file or directory
> ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
> ALSA lib conf.c:4154:(_snd_config_evaluate) function snd_func_concat returned 
> error: No such file or directory
> ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
> ALSA lib conf.c:4154:(_snd_config_evaluate) function snd_func_refer returned 
> error: No such file or directory
> ALSA lib conf.c:4633:(snd_config_expand) Evaluate error: No such file or 
> directory
> ALSA lib pcm.c:2211:(snd_pcm_open_noupdate) Unknown PCM default
> sox FAIL formats: can't open output file `default': snd_pcm_open error: No such 
> file or directory
> 
> 
(Continue reading)

Fmiser | 18 Aug 01:35 2010
Picon

Re: Execute PHP from Sox

> Chris Bagwell wrote:

> If you can find the full Alsa name then you can try "sox file
> -t alsa hw:0" or whatever in place of hw:0. Offhand, I don't
> know how to find the full device name. 

aplay -l

should list all the available devices.

--     Philip

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
Martin Kucej | 18 Aug 04:28 2010
Picon

Re: Execute PHP from Sox

> If you can  find the full Alsa name then you can try "sox file -t alsa hw:0" or 
>whatever
> in  place of hw:0. Offhand, I don't know how to find the full device name. 

I have tried -t alsa hw:0,0 and it did not work either, although the error 
message changed:

Home directory /var/www not ours.
ALSA lib pcm_hw.c:1401:(_snd_pcm_hw_open) Invalid value for card
sox FAIL formats: can't open output file `hw:0,0': snd_pcm_open error: No such 
file or directory

Hmm. A pitty. I wanted to write a web-based voice recorder. I may still do it, 
if this is going to work on Mac, let me try. Unfortunately, no cigar for Ubuntu.

Martin

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
Michael Chapman | 19 Aug 11:41 2010

Re: Execute PHP from Sox

Never got into this in detail, but as no-one has offered a solution 
....

If I SSH (remote login) to our 'sound machine' before anyone else
has used it; I can get it to play sound. But even after I have logged
out, anyone opening a GUI/Desktop gets no sound.

Vice-versa if someone has already opened a GUI/desktop
before I remote login.

Seems to be all something to do with ownership of sound devices
(which someone, earlier; did touch on).

BUT unless you want to do lots of tidying up afterwards
and/or reboot . . .
can you not do your exec command as the real user (a 'su' or
'sudo' command within the PHP) ... sorry I'm not a PHP user.

What you are trying sounds as if it might be simple with Perl ...

Just some experiences/thoughts

Michael

On Wednesday 18 August 2010 2:28 am, Martin Kucej wrote:
> > If you can  find the full Alsa name then you can try "sox file -t alsa
> > hw:0" or whatever
> > in  place of hw:0. Offhand, I don't know how to find the full device
> > name.
>
(Continue reading)

Jan Stary | 21 Aug 13:43 2010
Picon

Re: Execute PHP from Sox

On Aug 19 09:41:04, Michael Chapman wrote:
> Never got into this in detail, but as no-one has offered a solution 
> ....
> 
> If I SSH (remote login) to our 'sound machine' before anyone else
> has used it; I can get it to play sound. But even after I have logged
> out, anyone opening a GUI/Desktop gets no sound.
> 
> Vice-versa if someone has already opened a GUI/desktop
> before I remote login.

Many "GUIs/desktops" (such as KDE and similar) have their own sound server,
which gets started when the first user launches up the GUI, but does not
exit when the user exits. These sound-server typically open the audio
device exclusively.

> Seems to be all something to do with ownership of sound devices
> (which someone, earlier; did touch on).
> 
> 
> BUT unless you want to do lots of tidying up afterwards
> and/or reboot . . .
> can you not do your exec command as the real user (a 'su' or
> 'sudo' command within the PHP) ... sorry I'm not a PHP user.
> 
> What you are trying sounds as if it might be simple with Perl ...
> 
> Just some experiences/thoughts
> 
> Michael
(Continue reading)

pj | 18 Aug 07:08 2010
Picon

Re: Execute PHP from Sox

> I have tried -t alsa hw:0,0 and it did not work either,
> although the error message changed:
>   Home directory /var/www not ours.
>   ALSA lib pcm_hw.c:1401:(_snd_pcm_hw_open) Invalid value for card

Maybe hw:0,0 _is_ an invalid value ?
For a start, surely that comma should be a full-stop ?
Maybe your command-line user has an environment-variable set ?
Input ports are shown by  arecord -l
Output ports are shown by  aplay -l
Also useful:
  ls -l /dev/snd/
  cat /proc/asound/devices
It's a regrettable feature of ALSA that the hw:x.x numbers
are needed by the user (eg for sox) but that they're not easy
to get a clear list of.

As your command-line user, we know that
  sox song.ogg -d
works fine in the console, so what about
  sox song.ogg -t alsa hw:0.0
?
Like Philip said,  aplay -l  should list the available devices.

Regards,  Peter Billam

http://www.pjb.com.au       pj <at> pjb.com.au      (03) 6278 9410
"Was der Meister nicht kann,   vermöcht es der Knabe, hätt er
 ihm immer gehorcht?"   Siegfried to Mime, from Act 1 Scene 2

(Continue reading)

Martin Kucej | 18 Aug 16:29 2010
Picon

Re: Execute PHP from Sox

Hi Peter:

Thanks for you suggestions. I should have written more. My card and device 
numbers are 0 and 0 according to aplay -l.

These work in command line:
-t alsa hw:0
-t alsa hw:0,0

This does not work in command line:
-t alsa hw:0.0

None of them work when executed from PHP. It looks to me that ALSA only works 
with the current session user.

Best regards,
Martin

> Maybe hw:0,0 _is_ an invalid value ?
> For a start, surely that  comma should be a full-stop ?
> Maybe your command-line user has an  environment-variable set ?
> Input ports are shown by  arecord  -l
> Output ports are shown by  aplay -l
> Also useful:
>   ls -l  /dev/snd/
>   cat /proc/asound/devices
> It's a regrettable feature of  ALSA that the hw:x.x numbers
> are needed by the user (eg for sox) but that  they're not easy
> to get a clear list of.
> 
(Continue reading)


Gmane