Question

The SAY DIGITS function in Perl does not read from a variable that contains the STDOUT result from a command line executed in Perl, but it works when i assign any value to the variable.

#!/usr/bin/perl
use strict;

my $Hour = qx(date "+%I"); 

print "SAY DIGITS $Hour \"\"\n";

The extensions.conf file:

exten => 222,1,Answer()
exten => 222,2,AGI(time.sh)
exten => 222,3,Hangup()

The code should tell the caller the current time. simple as that.

Was it helpful?

Solution

The return value of qx(...) (and backticks and readpipe usually has a newline appended to it, and you usually want to chomp that value before you use it downstream.

my $Hour = qx(date "+%I"); 
chomp($Hour);

print "SAY DIGITS $Hour \"\"\n";

OTHER TIPS

You may want to use the Lingua::ENG::Numbers module on CPAN.

Lingua::ENG::Numbers converts numeric values into their English string equivalents.

Here is an example of how to use it:

#!/usr/bin/perl
use Lingua::ENG::Numbers;
my $hour       = 0 + qx(date "+%I"); 
my $minute     = 0 + qx(date "+%M");
my $hour_str   = "";
my $minute_str = "";


if(my $o = Lingua::ENG::Numbers->new($hour)) {
    $hour_str = $o->get_string;
};
if(my $o = Lingua::ENG::Numbers->new($minute)) {
    $minute_str = $o->get_string;
};

print "It's $hour_str $minute_str";

You will get an output like It's Seven Seventeen (that's the time on my timezone).

Should you need to get audio from that you can pipe it through espeak which is a speech synthesizer for English and other languages.

UPDATE: Ah, I see, so SAY DIGITS is already implemented in Asterisk.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top