From: http://www.oldskoolphreak.com/tfiles/voip/tts-imap.agi



#!/usr/bin/perl
#
# AGI Script that reads back e-mail from an IMAP account.
#
# Requires the Asterisk::AGI, Net::IMAP::Simple, and Email::Simple modules.
#
# Written by: Black Rathchet ([EMAIL PROTECTED])
#
# http://www.oldskoolphreak.com

use Net::IMAP::Simple;
use Email::Simple;
use Asterisk::AGI;
use File::Basename;
use Digest::MD5 qw(md5_hex);

my $server = 'localhost'; #INSERT YOUR SERVER HERE
my $username = 'mailuser'; #INSERT YOUR USERNAME HERE
my $password = 'password'; #INSERT YOUR PASSWORD HERE

sub speak(){
    $text = $_[0];

    my $hash = md5_hex($text);

    my $ttsdir = "/var/lib/asterisk/sounds/tts";
    my $cepoptions = "-p audio/sampling-rate=8000,audio/channels=1";

    my $wavefile = "$ttsdir/tts-$hash.wav";

    unless (-f $wavefile) {

        open(fileOUT, ">/var/lib/asterisk/sounds/tts/say-text-$hash.txt");
        print fileOUT "$text";
        close(fileOUT);

        my $execf="/opt/swift/bin/swift -f $ttsdir/say-text-$hash.txt -o 
$wavefile
$cepoptions";
        system($execf);

        unlink("$ttsdir/say-text-$hash.txt");
    }
    $filename = 'tts/'.basename('tts/'.basename($wavefile,".wav"));
    $AGI->stream_file($filename);
    unlink("$wavefile");
}

$AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();

# Create the object
my $imap = Net::IMAP::Simple->new($server) ||
        die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n";

# Log on
if(!$imap->login($username,$password)){
        &speak("Login failed: " . $imap->errstr . "\n");
        exit(64);
}

# Print the subject's of all the messages in the INBOX
my $nm = $imap->select('INBOX');
$AGI->stream_file('vm-youhave');
$AGI->say_number($nm);
#$AGI->stream_file('vm-INBOX');
$AGI->stream_file('vm-messages');

for(my $i = 1; $i <= $nm; $i++){

        my $es = Email::Simple->new(join '', @{ $imap->top($i) } );

        $AGI->stream_file('vm-message');
        $AGI->say_number($i);
        &speak($es->header('Subject'));
        $AGI->stream_file('vm-from');
        &speak($es->header('From'));
        &speak("1, Play, 2, Next, Pound, Exit");
}

$imap->quit;







http://www.oldskoolphreak.com/tfiles/voip/



















Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
--Bandwidth and Colocation provided by Easynews.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Reply via email to