Search code examples
perlasteriskfestivalagi

Using Festival from an Asterisk AGI script


This feels like a really silly problem but I just can't figure it out. I am writing an AGI script in Perl using Asterisk::AGI which needs to invoke Festival to read some text to the caller. I know that in the dialplan I can say

Festival('Hello caller','any')

and it will say 'Hello caller' and allow interruption by any key. The trick is doing that from the AGI script. If I do this:

$agi->exec('Festival', '"Hello caller"')

It will say 'Hello caller'. No problem. But I can't get it to deal with the potential for key interruption. It looks kind of like a second parameter, but also kind of not like one. I tried

$agi->exec('Festival', '"Hello caller"', 'any')

And it seems to ignore it completely (no key interruption takes place). I also tried

$agi->exec('Festival', q{"Hello caller",'any'})

And it says the 'any' bit, which leads me to be seriously confused about the quoting (the double quotes inside the string I pass was the only way I could get it to do more than say the first word).

$agi->exec('Festival', q{"Hello caller", 'any'})

Just ignores the 'any' bit entirely.

The only resources online that mention using Festival from an AGI script all talk about invoking it externally, saving it to a temporary file and then playing that back. Do I really have to go down that path? Shouldn't I be able to run any dialplan application at all with any arguments I like from an AGI?


Solution

  • Yes, you are able to execute applications like in the dialplan, with AGI exec. You have to separate arguments with a Pipe (|) character.

    Example exec Dial with options (examples/agi-enum.agi)

    if ($option) {
        $option .= '|' . $DEFAULTTIMEOUT if ($DEFAULTTIMEOUT);
        $AGI->verbose("Executing Dial $option\n",3);
        $res = $AGI->exec('Dial', $option);
    }
    

    For Festival, it should work like this:

    $agi->exec('Festival', '"Hello caller"|"any"');
    

    or

    $agi->exec('FESTIVAL "Hello caller"|"any"');