in reply to I'm banging my head with simple trick

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:

#!/usr/bin/perl -w # # Speaks the text in $ARGV[0]. # Caches text-to-speech conversions as 8-kHz .WAV files. use Asterisk::AGI; use File::Basename; use Digest::MD5 qw(md5_hex); use strict; # set up communications w/ Asterisk my $agi = new Asterisk::AGI; $agi->ReadParse(); # figure out the WAV file to use based on a hash of the text to say my ($text_to_say) = @ARGV; my $hash = md5_hex($text_to_say); my $sounddir = "/var/lib/asterisk/sounds"; my $wavefile = "$sounddir/say-text-$hash.wav"; # unless we have already cached this text-to-speed conversion, # create the WAV file using Festival's text2wav (expensive) unless (-f $wavefile) { require File::Temp; my (undef, $tmpfile) = File::Temp::tempfile(DIR => $sounddir); my $pid = open my $pipe, "|-"; die "can't fork: $!" unless (defined $pid); if (!$pid) { # child open STDOUT, ">$tmpfile" or die "can't redir to $tmpfile: $!"; exec qw( text2wave -F 8000 - ); # text->speech conv; 8-kHz WAV + output die "exec in child failed: $!"; } else { # parent print $pipe $text_to_say; close $pipe; waitpid $pid, 0; # wait until text->speech conv. is done rename $tmpfile, $wavefile or die "can't rename $tmpfile to $wavefile: $!"; } } # stream the WAV file down the phone line $agi->stream_file(basename($wavefile, ".wav"));

Cheers,
Tom

Replies are listed 'Best First'.
Re^2: I'm banging my head with simple trick
by Anonymous Monk on Oct 07, 2004 at 00:28 UTC
    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