03.14.05
Posted in Coding at 1:34 pm by Craig
I thought I’d post a separate message just to say that over time I’ve modified my vonage voicemail to mp3 conversion script, to not use bad temporary files, fix some problems with caller id info, and other bits. The
new script is:
#!/usr/bin/perl
use MIME::Parser;
$p = new MIME::Parser;
$p->output_to_core(1);
$e = $p->parse(\*STDIN);
use IPC::Open2;
my ($wav_pipe, $mp3_pipe);
open2($mp3_pipe, $wav_pipe, "/usr/bin/lame",
"--preset", "phone",
"-v",
"-q", "0",
"-V", "9",
"--quiet",
"-",
"-");
print $wav_pipe $e->parts(1)->bodyhandle->as_string;
close $wav_pipe
{
local $/;
$mp3=<$mp3_pipe>;
}
close $mp3_pipe;
$fh = $e->parts(1)->bodyhandle->open("w");
$fh->print($mp3);
$fh->close;
$e->parts(1)->head->replace("Content-type","audio/mpeg");
$e->parts(1)->head->mime_attr("content-type.name"=>"voice-mail.mp3");
$e->parts(0)->bodyhandle->as_string =~ /^From: (.*)/m
and $callerid=$1
or $callerid="Unknown";
$b=$e->head->replace("From",""$callerid" <voicemail\@hughes-family.org>");
$e->head->replace("Subject","Voicemail from $callerid");
$e->sync_headers(Length=>"COMPUTE");
$e->print;
Permalink