slapcast.com blog

voicemail2twitter.rb

August 16, 2007 · No Comments

Quickly: with this script and a free k7.net account you can post voicemail messages to your twitter account.

On Saturday I gave a quick demo at barcampdc on a ruby script I wrote called voicemail2twitter.rb.

This was the barebones 5 minute slideshow:

And here is the code:

#! /usr/bin/env ruby

require 'rubygems'
require_gem 'actionmailer'
require 'twitter'

ActionMailer::Base.smtp_settings = {
  :address => 'localhost',
  :port => 25,
  :domain=> 'slapcast.com',
}
ActionMailer::Base.delivery_method = :smtp

class Mailman < ActionMailer::Base
  def receive(email)
    if email.has_attachments?
      for attachment in email.attachments

        base_dir = "/home/barcampdcaudio/web/"
        wav_name = "#{Time.now.to_i}-#{rand(1000)}"
        wav_path = "#{base_dir}#{wav_name}"
        mp3_path = "#{wav_path}.mp3"

        File.open(wav_path,File::CREAT|File::TRUNC|File::WRONLY,0666){ |f|
          f.write(attachment.read)
        }

        #convert wav to mp3
        system("/usr/bin/sox #{wav_path} -t wav -s -w - | /usr/local/bin/lame --resample 22 -v -q 0 -V 9 --quiet - #{mp3_path}")
        system("chmod 777 #{mp3_path}")  #yes, probably don't need a system call for this

        mp3_url = "http://slapcast.com/m/#{wav_name}"

        #post the link to twitter
        Twitter::Base.new('barcampdcaudio', 'twitter_password_goes_here').update("#{mp3_url}.mp3")

      end
    end
  end
end

Mailman.receive(STDIN.read)

→ No CommentsCategories: barcampdc · ruby · twitter

Twittergram - new slapcast.com feature

June 29, 2007 · No Comments

Dave Winer wrote a cool webservice called twittergram that posts small audio files to your twitter account of choice (as well as a global account twitogram). I combined this with slapcast’s support for podcasting by telephone, so now you can post directly to twitter from slapcast.

Here is the preference screen for a logged-in slapcast user:

This is the link to twitter prefs from the dashboard:

known bugs: there is a preference called “Also post to the global twitogram account” but it doesn’t do anything yet. It ALWAYS posts to twitogram right now.

Dave — thanks for creating twittergrams!

→ No CommentsCategories: Uncategorized