Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm banging my head with Perl AGI script to produce wav file to be streamed with Festival's text2wave utility.
I have two lines of code:
------------------------------------
system('echo "' . $text . '" | text2wave -scale 1.5 -F 8000 -o ' . $fi +lename . ' - '); system('echo "' . $text . '" | text2wave -eval "(voice_cmu_us_slt_arctic_hts)" -scale 1.5 -F 8000 -o ' . $filename . +' - ');
------------------------------------

Above line works, but with default voice. Line below doesn't work anymore (it doesn't produce any output wav file) although same line from command line works. Does system command strip or alter any characters ?

Any hint, opinion, I've lost any patience with this one so please help,

Regards,

Robert.

Replies are listed 'Best First'.
Re: I'm banging my head with simple trick
by tmoertel (Chaplain) on Oct 06, 2004 at 23:23 UTC
    For security reasons, I almost always use the forms of system and exec that take a list of arguments rather than a single string. These forms bypass the system shell, and so they're a bit more limited, but they are also free of quoting problems.

    Most likely, it's a quoting problem that's behind your issue. Try replacing your call to system with print to see what exactly you're passing.

    If you want to see how to do it the other way, here's some code (taken from my talk Fun with Asterisk and Perl) that shows how to use the list form of exec to invoke Festival and stream the result back to Asterisk:

    Cheers,
    Tom

      Hi,

      thanks for code. That was exactly my startup, but the problem arised when I tried to change Festival's default voice. I managed to do it with say-text.pl, but am still struggling with get-weather.pl. I have strange feeling that Perl scripts are somehow in different environment when run from Asterisk that plain run...

      Are you using your code with latest Asterisk and Festival ? If you do, then I'm doing something wrong...

      Regards,

      Robert.

        I have strange feeling that Perl scripts are somehow in different environment when run from Asterisk that plain run.
        Yes, that's usually the case. When you're testing your scripts from the command line, they are running as you and have the same privileges as your login shell. However, when run by Asterisk, which is often installed under its own account, they are run as the Asterisk user and with its privileges.

        For this reason, it's a good idea to double-check any files you need to access or programs you need to run to make sure that their permissions allow access by Asterisk's account. In particular, check out the permissions of files and directories in Festival's voices/us/cmu_us_slt_arctic_hts/ directory.

        Per your other question, no, I'm not using the most recent Asterisk and Festival releases. I'm using the stock Fedora Core 1 Festival and a development version of Asterisk that I built about six months ago.

        Cheers,
        Tom

Re: I'm banging my head with simple trick
by ikegami (Patriarch) on Oct 06, 2004 at 21:35 UTC

    You're surely better off using open("|..."), especially considering the problem is probably in the argument passed to echo. (quotes, new lines, other shell special characters?)

    $text = "lots of text\n" x 150; $filename = 'FILENAME.WAV'; open(TEXT2WAVE, '|text2wave -eval "(voice_cmu_us_slt_arctic_hts)" -sca +le 1.5 -F 8000 -o ' . $filename . ' - ') or die("Can't execute text2wave\n"); # Autoflush TEXT2WAVE: { my $f = select(TEXT2WAVE); $|=1; select($f); } print TEXT2WAVE ($text); close(TEXT2WAVE);
Re: I'm banging my head with simple trick
by ides (Deacon) on Oct 06, 2004 at 21:28 UTC
    Try building your entire command into a scalar and then just pass the scalar to system(). This has always helped me to remove any quoting problems.

    Frank Wiles <frank@wiles.org>
    http://www.wiles.org