Twitter2Mp3
From Rabbi Blog
I have no idea if this will go anywhere and the concept came from listening to Adam Curry on No Agenda.
Idea
Premise: parse Twitter feed using Perl, utilize Text2Wav (Festival) to convert to a wav file and then LAME encode the result to mp3.
text2wave -F 16000 htt.txt -o test2.wav
lame -s 8 test2.wav test2.mp3
Audio Result
<flashmp3>http://www.rabbibob.com/cstrike/20090324_twitter.mp3%7Cautostart=no%7Cloop=no%7CfirstTrackName=Twitter2Mp3 Example</flashmp3>
Text
- replaced http urls with 'weblink'
- reduced multiple .. to .
- replaced minor emoticons with words
- reversed tweet order (now reads oldest -> newest)
- reports # of tweets since last update (200 max)
- added extra line break - helps text2wav 'breath' between tweets
There have been 200 tweets since the last update Tweet 1 pralphman said Checking out some film trailers on apple.com Seems there are some fairly good comedies coming in the next few months. Tweet 2 Oblivion said Crap. Yesterday was the first day in 42 that I missed doing at least the body test on the #WiiFit. Foo, its disappointed with me. Tweet 3 dashdrum said @toyotaboy yeah, but my co-workers don't know they aren't clean :-) Tweet 4 dashdrum said Hot chocolate and pop-tarts. Breakfast of champions! Tweet 5 fortheinsane said @dashdrum what flavour pop tarts? Tweet 6 draithon said @UberSchwarz u may feel like cattle when they herd u on, but hey for the prices they charge I'm not complaining, ok I want more destinations Tweet 7 dashdrum said @fortheinsane Brown sugar cinnamon. The best one! Tweet 8 draithon said I'm overly concerned about a proposal that could cap a persons compensation for their job The interpretations of that law could be disaster Tweet 9 draithon said America was built on hard work. If you cap wages, where is motivation going to be. Hate to say it but greed is a great motivator. Tweet 10 draithon said I'm not in finance, but I can see this proposal being interpreted & construed against other jobs. Ultimately hurting the middle class. Tweet 11 draithon said I usually try to stay away from politics, but the last 18 months - 2 years I have been overly studying & paying better attention to them. Tweet 12 draithon said lol Tweet 13 draithon said Dam @twitterfox is getting aggravating. It submitted the tweet before I was ready to. Just another thing for this monday I guess Tweet 14 adamcurry said Preferred format for promos is mp3 Tweet 15 marcapitman posted Great Foxtrot cartoon on Twitter and parenting Weblink Props to @trwl Tweet 16 cc_chapman posted SXSW Was a Success For Me - Weblink Tweet 17 tomit posted Have maxed out my Mafia members of Facebook. If anyone wants to play or wants to add me here's the link to my FB page. Weblink Tweet 18 tomit posted I will be accepting almost all adds on Facebook for a little while. Weblink Tweet 19 thurrott said Good morning. I emerge from my cave this morning with a few chapters done ("Windows 7 Secrets") but hundreds of screenshots yet to take. Joy Tweet 20 Oblivion said Should shave my head today. Sunburn dictates otherwise. Tweet 21 adamcurry said Done with accountants. Astoundingly simple. Turns out pysical gold makes life easier in that regard smile Tweet 22 JohnCleese posted Just had a web minion add me to the Weblink twitter directory under: #British #Actor #Writer Tweet 23 Shultzman said woke up to sunny skies and the sound of birds singing. I LOVE SPRING!!! Tweet 24 merlyn said completely off oxycontin; didn't even take any ibuprofen between 9pm and 6am. hardest part has passed. tomorrow: bandages off!
Fetch Code
#!/usr/bin/perl use strict; use warnings; use Net::Twitter; my $twit = Net::Twitter->new({username=>"user", password=>"password" }); my $last_id=1366625646; #prime the last_id for first run if (-e "bookmark.txt") #get the last_id { open BOOKMARK, "<", "bookmark.txt" or die $!; while (<BOOKMARK>) { if ($_>$last_id) #keep track of the most recent update to dump to bookmark later { $last_id=$_; } } close BOOKMARK; } my @timeline = $twit->friends_timeline({count => 200, since_id => $last_id }); my $timeline; my $i=0; while ($timeline[0][$i]) { $i++; } print "There have been $i tweets since the last update\n\n"; my $counter=1; $i--; for my $textout (reverse 1 .. $i) { my $location=$timeline[0][$textout]{'user'}{'location'}; my $id=$timeline[0][$textout]{'id'}; if ($id>$last_id) #keep track of the most recent update to dump to bookmark later { $last_id=$id; } my $screenname=$timeline[0][$textout]{'user'}{'screen_name'}; my $msg=$timeline[0][$textout]{'text'}; my $updatetype; if ($msg=~m/http/) { $updatetype="posted"; } else {$updatetype="said"} # Need to develop a scrubber routine that takes an input file $msg=~s/https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?/Weblink /g; $msg=~s/RT/retweet/g; $msg=~s/\.\./\./g; $msg=~s/:\)/smile/g; $msg=~s/;\)/wink/g; $msg=~s/:\(/frown/g; # Do I want a file list of people to NOT put to the output? print "Tweet $counter $screenname $updatetype $msg\n\n"; $counter++; } open BOOKMARK, ">", "bookmark.txt" or die $!; #set the last_id for the future print BOOKMARK "$last_id"; close BOOKMARK;
Code Notes
$msg=~s/https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?/link /g;
Fetch Result
results in (chopped)
$VAR1 = [ [ { 'source' => 'web', 'favorited' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ), 'truncated' => $VAR1->[0][0]{'favorited'}, 'created_at' => 'Sat Mar 21 10:27:17 +0000 2009', 'text' => '@uberschwarz @draithon short HDR bit discussed on TFTTF #346', 'user' => { 'location' => 'Behind you...', 'followers_count' => 99, 'profile_image_url' => 'http://s3.amazonaws.com/twitter_production/profile_images/105270932/3371878294_7e0723920e_normal.jpg', 'protected' => $VAR1->[0][0]{'favorited'}, 'name' => 'Rabbi Bob', 'url' => 'http://www.rabbibob.com/', 'id' => 2955291, 'description' => 'degradable', 'screen_name' => 'rabbibob' }, 'in_reply_to_user_id' => 3708131, 'id' => 1365343447, 'in_reply_to_status_id' => undef, 'in_reply_to_screen_name' => 'UberSchwarz' } ] ]