[asterisk-users] Re: Voicemail IMAP
Derek Whitten
derek at kfuq.net
Fri Jan 12 07:27:15 MST 2007
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 (blackratchet at blackratchet.org)
#
# 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/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://lists.digium.com/pipermail/asterisk-users/attachments/20070112/8fd0fdbd/signature.pgp
More information about the asterisk-users
mailing list