문제

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.

도움이 되었습니까?

해결책

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";

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top