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)

Jonas Kellens | 17 Aug 10:20 2010
Picon

First time use of SoX : converting wav to mono 8000Hz

Hello list,

hope you can help me out.


2 files :

[root <at> asterisk testing]# file testExtended.wav
testExtended.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 44100 Hz
[root <at> asterisk testing]# file testLong.wav
testLong.wav: RIFF (little-endian) data, WAVE audio, 20294 channels 1414676809 Hz

to mono :

[root <at> asterisk testing]# sox testExtended.wav -r 8000 -c1 testExtended2.wav resample -ql
sox sox: effect `resample' is deprecated; see sox(1) for an alternative
[root <at> asterisk testing]# sox testLong.wav -r 8000 -c1 testLong2.wav resample -ql
sox sox: effect `resample' is deprecated; see sox(1) for an alternative
sox effects: resample clipped 2 samples; decrease volume?

afterwards :

[root <at> asterisk testing]# file testLong2.wav
testLong2.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
[root <at> asterisk testing]# file testExtended2.wav
testExtended2.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz

But my Asterisk-server can not open them :

[root <at> asterisk testing]# asterisk -rx "file convert testExtended2.wav testExtended2.alaw"
Unable to open input file: testExtended2.wav
[root <at> asterisk testing]# asterisk -rx "file convert testLong2.wav testLong2.alaw"
Unable to open input file: testLong2.wav

The file has decreased in file size :

-rw-r--r-- 1 root root 885K 2010-08-17 08:59 testExtended2.wav
-rw-r--r-- 1 root root 9.6M 2010-08-17 08:57 testExtended.wav



I can play the original and the resampled file perfectly in Gnome Mplayer, but my Asterisk-server can not read the file to convert it to alaw. Could there be something wrong with the wav-file ?!


Kind regards,

Jonas.
------------------------------------------------------------------------------
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 
_______________________________________________
Sox-users mailing list
Sox-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-users
Jan Stary | 17 Aug 11:53 2010
Picon

Re: First time use of SoX : converting wav to mono 8000Hz

> [root <at> asterisk testing]# file testExtended.wav
> testExtended.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM,  
> 16 bit, stereo 44100 Hz

What does soxi(1) say about the file?

> [root <at> asterisk testing]# file testLong.wav
> testLong.wav: RIFF (little-endian) data, WAVE audio, 20294 channels  
> 1414676809 Hz

I very much doubt that you have a 202294-chanel file with a samplerate
of 1414676809 Hz. The wav header of this file is probably broken. What
does soxi say about the file. Is play(1) able to play it?

> to mono :
> sox testExtended.wav -r 8000 -c1  testExtended2.wav resample -ql
> sox sox: effect `resample' is deprecated; see sox(1) for an alternative

Why are you using deprecated effects??

sox -V testExtended.wav testExtended2.wav remix - rate 8000
sox -V testExtended.wav -c 1 -r 8000 testExtended2.wav

> [root <at> asterisk testing]# sox testLong.wav -r 8000 -c1 testLong2.wav  
> resample -ql
> sox sox: effect `resample' is deprecated; see sox(1) for an alternative
> sox effects: resample clipped 2 samples; decrease volume?

Again, why are you using 'resample'? That's a deprecated alias for 'rate',
which you already specified with the '-r 8000'.

> afterwards :
> [root <at> asterisk testing]# file testLong2.wav
> testLong2.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16  
> bit, mono 8000 Hz

Looks good; what does soxi(1) say about the file?
Can you play the resulting mono/8000 file?

> [root <at> asterisk testing]# file testExtended2.wav
> testExtended2.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM,  
> 16 bit, mono 8000 Hz

It seems that sox somehow converted the original file (which most likely
is _not_ a 20294c/1414676809Hz file) into a mono/8000.  It would be useful
to know the output of 'sox -V' wehn running this.  Are you able to play
the file?

> But my Asterisk-server can not open them :
> [root <at> asterisk testing]# asterisk -rx "file convert testExtended2.wav  
> testExtended2.alaw"
> Unable to open input file: testExtended2.wav
> [root <at> asterisk testing]# asterisk -rx "file convert testLong2.wav  
> testLong2.alaw"
> Unable to open input file: testLong2.wav

That has nothing to do with sox, right?
Ask on the asterisk mailing list.

> The file has decreased in file size :
> -rw-r--r-- 1 root root 885K 2010-08-17 08:59 testExtended2.wav
> -rw-r--r-- 1 root root 9.6M 2010-08-17 08:57 testExtended.wav

Of course. Both the number of channels and the sample rate have been
reduced, so the file size got reduced, too. (Are you sure you know what
a 'sample rate' is?)

The numbers seem right: the new file's size is about
a ((1*8000)/(2*44100))-th of the old one.

> I can play the original and the resampled file perfectly in Gnome  
> Mplayer, but my Asterisk-server can not read the file to convert it to  
> alaw. Could there be something wrong with the wav-file ?!

9.6M and 885K is small enough to put the files
somewehere on the web so we can look at them.

------------------------------------------------------------------------------
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 
Jonas Kellens | 17 Aug 12:49 2010
Picon

Re: First time use of SoX : converting wav to mono 8000Hz

On 08/17/2010 11:53 AM, Jan Stary wrote:
> What does soxi(1) say about the file?
>    

The original files :

[root <at> asterisk testing]# soxi testExtended.wav

Input File     : 'testExtended.wav'
Channels       : 2
Sample Rate    : 44100
Precision      : 16-bit
Duration       : 00:00:56.57 = 2494953 samples = 4243.12 CDDA sectors
Sample Encoding: 16-bit Signed Integer PCM

[root <at> asterisk testing]# soxi testLong.wav

Input File     : 'testLong.wav'
Channels       : 2
Sample Rate    : 44100
Precision      : 16-bit
Duration       : 00:01:27.05 = 3839052 samples = 6529 CDDA sectors
Sample Encoding: 16-bit Signed Integer PCM

> Why are you using deprecated effects??
>
> sox -V testExtended.wav testExtended2.wav remix - rate 8000
> sox -V testExtended.wav -c 1 -r 8000 testExtended2.wav
>    

[root <at> asterisk testing]# sox -V testLong.wav -c 1 -r 8000 testLong3.wav
sox: SoX v14.2.0
sox formats: detected file format type `wav'

Input File     : 'testLong.wav'
Channels       : 2
Sample Rate    : 44100
Precision      : 16-bit
Duration       : 00:01:27.05 = 3839052 samples = 6529 CDDA sectors
Sample Encoding: 16-bit Signed Integer PCM
Endian Type    : little
Reverse Nibbles: no
Reverse Bits   : no

Output File    : 'testLong3.wav'
Channels       : 1
Sample Rate    : 8000
Precision      : 16-bit
Duration       : 00:01:27.05 = 696427 samples ~ 6529 CDDA sectors
Sample Encoding: 16-bit Signed Integer PCM
Endian Type    : little
Reverse Nibbles: no
Reverse Bits   : no
Comment        : 'Processed by SoX'

sox sox: effects chain: input      44100Hz 2 channels 16 bits (multi)
sox sox: effects chain: rate       44100Hz 2 channels 16 bits
sox sox: effects chain: mixer      8000Hz 2 channels 16 bits (multi)
sox sox: effects chain: output     8000Hz 1 channels 16 bits (multi)
sox effects: rate clipped 13 samples; decrease volume?

> Looks good; what does soxi(1) say about the file?
> Can you play the resulting mono/8000 file?
>    

[root <at> asterisk testing]# soxi testLong3.wav

Input File     : 'testLong3.wav'
Channels       : 1
Sample Rate    : 8000
Precision      : 16-bit
Duration       : 00:01:27.05 = 696427 samples ~ 6529 CDDA sectors
Sample Encoding: 16-bit Signed Integer PCM

I can play this file in Gnome Mplayer.

Does this mean the resulting Mono 8000Hz file is correct ?! If so, the 
problem indeed lies with the Asterisk software. A question there has 
been asked but left unanswered.

If you are 100% sure the resulting file testLong3.wav should be a 
correct wav-file, then this topic is closed.

Thank you for your help.

Kind regards,

Jonas.

------------------------------------------------------------------------------
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 
Jan Stary | 17 Aug 14:40 2010
Picon

Re: First time use of SoX : converting wav to mono 8000Hz

On Aug 17 12:49:41, Jonas Kellens wrote:
> On 08/17/2010 11:53 AM, Jan Stary wrote:
> > What does soxi(1) say about the file?
> >    
> 
> The original files :
> 
> [root <at> asterisk testing]# soxi testExtended.wav
> 
> Input File     : 'testExtended.wav'
> Channels       : 2
> Sample Rate    : 44100
> Precision      : 16-bit
> Duration       : 00:00:56.57 = 2494953 samples = 4243.12 CDDA sectors
> Sample Encoding: 16-bit Signed Integer PCM
> 
> [root <at> asterisk testing]# soxi testLong.wav
> 
> Input File     : 'testLong.wav'
> Channels       : 2
> Sample Rate    : 44100
> Precision      : 16-bit
> Duration       : 00:01:27.05 = 3839052 samples = 6529 CDDA sectors
> Sample Encoding: 16-bit Signed Integer PCM

This looks better. I don't know why your installation of file(1)
said it was a zillion-channel file of goooglilion Hz samplerate.

> > Why are you using deprecated effects??
> >
> > sox -V testExtended.wav testExtended2.wav remix - rate 8000
> > sox -V testExtended.wav -c 1 -r 8000 testExtended2.wav
> >    
> 
> [root <at> asterisk testing]# sox -V testLong.wav -c 1 -r 8000 testLong3.wav
> sox: SoX v14.2.0
> sox formats: detected file format type `wav'
> 
> Input File     : 'testLong.wav'
> Channels       : 2
> Sample Rate    : 44100
> Precision      : 16-bit
> Duration       : 00:01:27.05 = 3839052 samples = 6529 CDDA sectors
> Sample Encoding: 16-bit Signed Integer PCM
> Endian Type    : little
> Reverse Nibbles: no
> Reverse Bits   : no
> 
> 
> Output File    : 'testLong3.wav'
> Channels       : 1
> Sample Rate    : 8000
> Precision      : 16-bit
> Duration       : 00:01:27.05 = 696427 samples ~ 6529 CDDA sectors
> Sample Encoding: 16-bit Signed Integer PCM
> Endian Type    : little
> Reverse Nibbles: no
> Reverse Bits   : no
> Comment        : 'Processed by SoX'
> 
> sox sox: effects chain: input      44100Hz 2 channels 16 bits (multi)
> sox sox: effects chain: rate       44100Hz 2 channels 16 bits
> sox sox: effects chain: mixer      8000Hz 2 channels 16 bits (multi)
> sox sox: effects chain: output     8000Hz 1 channels 16 bits (multi)
> sox effects: rate clipped 13 samples; decrease volume?
> 
> 
> > Looks good; what does soxi(1) say about the file?
> > Can you play the resulting mono/8000 file?
> >    
> 
> [root <at> asterisk testing]# soxi testLong3.wav
> 
> Input File     : 'testLong3.wav'
> Channels       : 1
> Sample Rate    : 8000
> Precision      : 16-bit
> Duration       : 00:01:27.05 = 696427 samples ~ 6529 CDDA sectors
> Sample Encoding: 16-bit Signed Integer PCM
> 
> 
> I can play this file in Gnome Mplayer.

So sox did exactly what you told it to do: it converted
the original 2c/44k/16b file to a 1c/8k/16 file. What seems
to be the problem here?

> Does this mean the resulting Mono 8000Hz file is correct ?!

How would I know? You have played it in mplayer, so you know.
Technically, it's a 1c/8k/16b file, just as you wanted.

> If so, the 
> problem indeed lies with the Asterisk software. A question there has 
> been asked but left unanswered.
> 
> If you are 100% sure the resulting file testLong3.wav should be a 
> correct wav-file, then this topic is closed.

------------------------------------------------------------------------------
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 | 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

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

-Pascal
--

-- 
Homepage (http://organact.mine.nu)
Debian GNU/Linux (http://www.debian.org)
COMunité/LACIME: École de technologie supérieure (http://www.comunite.ca)

------------------------------------------------------------------------------
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
> 
> 

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. 

------------------------------------------------------------------------------
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:32 2010

Re: First time use of SoX : converting wav to mono 8000Hz


On Aug 17, 2010, at 5:49 AM, Jonas Kellens <jonas.kellens <at> telenet.be> wrote:

> 
> Does this mean the resulting Mono 8000Hz file is correct ?! If so, the 
> problem indeed lies with the Asterisk software. A question there has 
> been asked but left unanswered.
> 
> If you are 100% sure the resulting file testLong3.wav should be a 
> correct wav-file, then this topic is closed.
> 

Most these style telephony apps want ulaw or alaw encoding at 8 bit.  See sox man page on how to do that. At
minimum, it's strange to have a 8000hz file that is not 8 bits and is probably the main issue.  
------------------------------------------------------------------------------
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 
Jonas Kellens | 17 Aug 18:24 2010
Picon

SoX installed, but soxi not

Hello list,

using CentOS 5.4 64 bit :

bash-3.2# uname -a
Linux vps.hosting.net 2.6.18-194.3.1.el5xen #1 SMP Thu May 13 13:49:53 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux


SoX is installed :

bash-3.2# rpm -qa | grep sox
sox-12.18.1-1


But I can not use the command "soxi" :

bash-3.2# soxi 01Long.wav
bash: soxi: command not found

bash-3.2# locate soxi
bash-3.2#

bash-3.2# yum provides *soxi*
No Matches found


Is this normal ?


Kind regards,

Jonas.
------------------------------------------------------------------------------
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 
_______________________________________________
Sox-users mailing list
Sox-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-users
Chris Bagwell | 17 Aug 19:08 2010

Re: SoX installed, but soxi not

Your running an older version of SoX that doesn't include soxi.

SoX of today is much improved and often works very different then that
3 year old version.  It will be difficult to get accurate help from
mailing list without first upgrading.

Chris

On Tue, Aug 17, 2010 at 11:24 AM, Jonas Kellens
<jonas.kellens <at> telenet.be> wrote:
> Hello list,
>
> using CentOS 5.4 64 bit :
>
> bash-3.2# uname -a
> Linux vps.hosting.net 2.6.18-194.3.1.el5xen #1 SMP Thu May 13 13:49:53 EDT
> 2010 x86_64 x86_64 x86_64 GNU/Linux
>
>
> SoX is installed :
>
> bash-3.2# rpm -qa | grep sox
> sox-12.18.1-1
>
>
> But I can not use the command "soxi" :
>
> bash-3.2# soxi 01Long.wav
> bash: soxi: command not found
>
> bash-3.2# locate soxi
> bash-3.2#
>
> bash-3.2# yum provides *soxi*
> No Matches found
>
>
> Is this normal ?
>
>
> Kind regards,
>
> Jonas.
>
> ------------------------------------------------------------------------------
> 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
> _______________________________________________
> Sox-users mailing list
> Sox-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sox-users
>
>

------------------------------------------------------------------------------
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 

Gmane