Quantcast
Channel: Reza Samimi's Web Page » FreePBX tips and tricks
Viewing all articles
Browse latest Browse all 11

Playing Farsi digits in Asterisk

$
0
0

Here is the Asterisk AGI to play Farsi numbers. The script is meant to play numbers as big as 1000, so for bigger numbers you need to do some simple modifications.

Step 1)

Here is the AGI file:

#!/usr/bin/php -q
<?php
/*
This script takes a digit from Asterisk
DialPlan and reads the digit in Farsi

Developed by Reza Samimi
www.mehrdust.com
reza.samimi@mehrdust.com
*/

set_time_limit(30);
require('phpagi.php');
error_reporting(E_ALL);

$agi = new AGI();

$a = $argv[1];

$agi->verbose("your choise is: $a",3);

if (($a>=0) && ($a<100)) sefrTOsad($a);
else if (($a>=100) && ($a<1000)) sadTOhezar($a);

exit(0);

function sefrTOsad($num) {
    global $agi;

    $mod = $num % 10;
    $dv = floor($num / 10);
    $agi->verbose($mod." | ".$dv);
    if (($dv == 0) || ($dv==1)) $agi->stream_file("FarsiSounds/digits/$num");
    else if ($mod==0)
      $agi-> stream_file("FarsiSounds/digits/$num");
    else {
        $agi-> stream_file("FarsiSounds/digits/_".$dv."0");
        $agi-> stream_file("FarsiSounds/digits/$mod");
    }
}

function sadTOhezar($num) {
    global $agi;

    $mod = $num % 100;
    $dv = floor($num / 100);
    if ($mod==0)
      $agi-> stream_file("FarsiSounds/digits/$num");
    else {
        $agi-> stream_file("FarsiSounds/digits/_".$dv."00");
        sefrTOsad($mod);
    }
}

?>

Simply copy this file to your agi_bin folder (/var/lib/asterisk/agi_bin) and set the ownership and permissions accordingly.

You can find the sample digits here . Untar them in /var/lib/asterisk/sounds folder

Step 2)

Wherever necessary in your Asterisk dialplan call the AGI like this:

exten => *778,1,answer()
exten => *778,n(repeat),wait(1)
exten => *778,n,read(FarsiDigit,pls-enter-num-message-after-tone)
exten => *778,n,AGI(sayDigitsFarsi.php|${FarsiDigit})
exten => *778,n,goto(repeat)
exten => *778,n,hangup

Viewing all articles
Browse latest Browse all 11

Trending Articles