Categories

  • Apple (15)
  • Coding (4)
  • del.icio.us (14)
  • General (136)
  • Life (10)
    • Remodel (1)
  • Politics (16)
  • Project Steamroller (1)
  • Spam (11)
  • Sysadmin (9)
  • Tech/Geek (15)
  • Uncategorized (52)

Ye Olde Posts

  • March 2010 (1)
  • January 2010 (3)
  • December 2009 (1)
  • November 2009 (1)
  • October 2009 (2)
  • September 2009 (1)
  • August 2009 (3)
  • July 2009 (3)
  • June 2009 (2)
  • May 2009 (2)
  • April 2009 (1)
  • March 2009 (4)
  • February 2009 (2)
  • January 2009 (1)
  • December 2008 (1)
  • September 2008 (1)
  • July 2008 (1)
  • May 2008 (5)
  • April 2008 (2)
  • March 2008 (9)
  • February 2008 (5)
  • January 2008 (6)
  • December 2007 (7)
  • November 2007 (2)
  • October 2007 (6)
  • August 2007 (7)
  • July 2007 (2)
  • June 2007 (3)
  • May 2007 (3)
  • April 2007 (8)
  • March 2007 (8)
  • February 2007 (10)
  • January 2007 (3)
  • December 2006 (2)
  • November 2006 (1)
  • October 2006 (2)
  • August 2006 (2)
  • July 2006 (2)
  • June 2006 (2)
  • May 2006 (5)
  • April 2006 (2)
  • February 2006 (1)
  • January 2006 (2)
  • December 2005 (2)
  • November 2005 (2)
  • October 2005 (3)
  • September 2005 (1)
  • August 2005 (1)
  • July 2005 (3)
  • June 2005 (3)
  • May 2005 (1)
  • April 2005 (1)
  • March 2005 (1)
  • February 2005 (4)
  • January 2005 (1)
  • December 2004 (3)
  • October 2004 (3)
  • July 2004 (1)
  • April 2004 (5)
  • March 2004 (5)
  • February 2004 (5)
  • January 2004 (3)
  • December 2003 (2)
  • November 2003 (9)
  • October 2003 (5)
  • September 2003 (4)
  • August 2003 (3)
  • July 2003 (2)
  • June 2003 (8)
  • May 2003 (5)
  • April 2003 (4)
  • March 2003 (10)
  • February 2003 (25)
  • January 2003 (12)

Vonage voicemail WAV to MP3 conversion

Nov13
2003
8 Comments Written by Craig

Latest update: Vonage has modified the WAV format that they include in the attachment, breaking the above scripts. See this new post detailing what to do now

Ok, so Vonage voicemail can be delivered by email. Except the attachment comes as a WAV file, so it’s HUGE if the voicemail is of any length at all. Can’t be helped that I have to receive these gigantic files, but I’ll be damned if I store them in WAV format, or if I have to download them to my MUA when they’re that big. So, to work around this “feature”, I wrote a perl one-liner which can be called from procmail to replace the WAV attachment with an MP3. To have this work, you’ll need to install lame, MIME::Parser, and of course perl.

# Check if this is a voicemail message from Vonage
:0fw
* ^X-Mailer: CommWorks
* ^From: .*your_phone_number@vm.vonage.com.*
| /usr/bin/perl -MMIME::Parser -e '$p = new MIME::Parser; $p->output_to_core(1); $e = $p->parse(*STDIN); $f = "/tmp/$$"; open(PIPE, "|/usr/bin/lame --preset phone -v -q 0 -V 9 --quiet - $f"); print PIPE $e->parts(0)->bodyhandle->as_string; close PIPE; open(PIPE,"< :bytes",$f); { local $/; $mp3=<PIPE>; } close PIPE; $fh = $e->parts(0)->bodyhandle->open("w"); $fh->print($mp3); $fh->close; $e->parts(0)->head->replace("Content-type","audio/mpeg"); $e->parts(0)->head->mime_attr("content-type.name"=>"voice-mail.mp3"); $e->sync_headers(Length=>"COMPUTE"); $e->print; unlink($f);'

UPDATE: Vonage has fixed voicemail emails so that they now include caller-id information in them. But they did it by inserting a MIME part in the mail. So the script needs to change to the following (also X-Mailer changed, and this also now rewrites the From line with callerID info from the message body):
this is a voicemail message from Vonage

:0fw
* ^X-Mailer: UTStarcom
* ^From: .*your_phone_number@vm.vonage.com.*
| /usr/bin/perl -MMIME::Parser -e '$p = new MIME::Parser; $p->output_to_core(1); $e = $p->parse(*STDIN); $f = "/tmp/$$"; open(PIPE, "|/usr/bin/lame --preset phone -v -q 0 -V 9 --quiet - $f"); print PIPE $e->parts(1)->bodyhandle->as_string; close PIPE; open(PIPE,"< :bytes",$f); { local $/; $mp3=<PIPE>; } close 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: (.*?)r$/m; $b=$e->head->replace("From","$1 <voicemail @hughes-family.org>"); $e->sync_headers(Length=>"COMPUTE"); $e->print; unlink($f);'

UPDATE:WordPress consistently buggers up the formatting of perl documents. The perl script from above, updated, cleaned up is available for download here

Posted in Tech/Geek
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

8 Comments

  1. Aaron Freimark's Gravatar Aaron Freimark
    3/22/2004 at 3:51 am | Permalink

    This would be great… unfortunately your blog program is munging your code. Can you post a <pre>-formatted version? Thanks.

    Reply
  2. Dobs's Gravatar Dobs
    7/3/2004 at 5:43 am | Permalink

    I am having a little trouble getting this sctipt to work correctly
    I currently get an email with a blank From address, and an mp3 attachment of 0 bytes and no sound.

    I understand what most of the code above is doing, but i must be missing something. Can you please look over this and see what i may be doing wrong.

    This is what i have:

    #!/usr/bin/perl
    #
    use MIME::Parser;
    use IO::File;

    $p = new MIME::Parser;
    $p->output_to_core(1);
    $e = $p->parse(*STDIN);

    $out = "/tmp/$$";
    open(PIPE, "|/usr/bin/lame --preset phone -v -q 0 -V 9 -quiet - $out");
    print PIPE $e->parts(1)->bodyhandle->as_string;
    close PIPE;

    open(PIPE,"<:bytes ",$out);
    { local $/; $mp3; }
    close 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: (.*?)r$/m;

    $b=$e->head->replace("From","$1 ");
    $e->sync_headers(Length=>"COMPUTE");
    $e->print;

    unlink($out);

    Reply
  3. craig's Gravatar craig
    7/6/2004 at 4:41 am | Permalink

    Looks like you have a copy/paste error there on the second open() call. Is that what you actually have in your code?

    Reply
  4. Dobs's Gravatar Dobs
    7/7/2004 at 4:02 pm | Permalink

    I found the error. Thank you.
    It was not a copy paste error, but i think an error with your blog.
    it did not show the

    open(PIPE,”<:bytes ",$f); { local $/; $mp3=; } close PIPE;

    correctly. it was missing $mp3 =PIPE because it was surrounded by LT and GT signs.

    After doing some research on perl and some of the methods you were using, i changed some things. i have it here if you are interested :

    use MIME::Parser;
    use IO::File;

    $p = new MIME::Parser;
    $p->output_to_core(1);
    $e = $p->parse(*STDIN);
    $f = "/tmp/$$";

    open(PIPE, "|/usr/bin/lame --preset phone -v -q 0 -V 9 -quiet - $f");
    print PIPE $e->parts(1)->bodyhandle->as_string;
    close PIPE;

    if( open(PIPE,"<:bytes ",$f) ) {
    if( $fh = $e->parts(1)->bodyhandle->open("w") ) {
    my $buffer;
    while( read(PIPE, $buffer, 10240) > 0 ) ### read chunks of 10KB at a time
    {
    $fh->print($buffer);
    }
    $fh->close;
    } else {
    warn "Error opening MIME part for writing: $!";
    }
    close PIPE;
    } else {
    warn "Error opening mp3 file $f: $!";
    }

    $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 =~ m/((d+))/m;

    #$b=$e->head->replace("From","$1 ");
    $e->sync_headers(Length=>"COMPUTE");
    $e->print;

    unlink($f);

    Again thanks for the initial script. Great job.

    Reply
  5. tobiasly's Gravatar tobiasly
    3/13/2005 at 8:20 am | Permalink

    All of these posts have wrong formatting! WordPress doesn’t seem to be very Perl-friendly. :)

    I have posted a correct, working version of this script here: http://www.tobiasly.com/index.php?itemid=291

    Thanks for the script to work with!

    Reply
  6. Craig's Gravatar Craig
    3/14/2005 at 12:04 pm | Permalink

    Sorry about the format munging — WordPress keeps changing the way it does that, I keep going in and fixing the DB to format things properly, and then they break again with the next point release. Very annoying. I’ll just stick a link to the source code file.

    Reply
  7. tobiasly's Gravatar tobiasly
    3/19/2005 at 12:33 pm | Permalink

    Thanks for the update! The IPC::Open2 use is a good idea, I was wanting to clean up the tempfile use but since I’m the only one who uses my box I wasn’t too worried about it at the moment. I’ll update my post to reflect it!

    Reply
  8. tobiasly's Gravatar tobiasly
    3/22/2005 at 12:29 pm | Permalink

    A couple more things:
    * You may want to store your source code as .pl.txt instead of just .pl, so people don’t accidentally launch the Perl script when trying to view it!
    * I’m pretty sure you want to remove the last two lines of your current script (the unlink and rmdir); I’m assuming these are left-over from the tmpfile version.
    * Every program I use to open the converted MP3s thinks the duration is half as long as it actually is. I’m guessing this is a LAME issue, but I can’t see what parms might fix it. Does anyone have ideas?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

CAPTCHA Image
Refresh Image

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

Translate

EnglishFrenchGermanItalianPortugueseRussianSlovenianSpanish

Search

Recent Comments

  • Craig on On the efficiency of Virtual Machines
  • flickr.com/photos/jm on On the efficiency of Virtual Machines
  • jmason on Neat. A new way to track website visitors!
  • jmason on On the time domain, with regard to spam
  • pooya on Interesting Tivo trivia bit

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

EvoLve theme by Blogatize  •  Powered by WordPress Craigalog
Craig's musings