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


In reply to Re: I'm banging my head with simple trick by tmoertel
in thread I'm banging my head with simple trick by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.