Friday, December 11, 2009

Audio based interfaces for Twitter Part 3

At this point, I have the ability to listen to my /home feed on a rotation of my choosing, as well as @public_timeline, and have made an online radio station to explain/share the experience. The very night that I implemented the bluetooth audio feed of my /home feed, I said to myself: "How great would it be if I could actually tweet via voice?". I already knew what the state of speech to text offerings for Linux which was there really isn't much out there from what I could tell. Then on November 10th, I saw the following post on It took me about a minute to think of an easy way to do the same thing except send the message to Twitter.

Thanks to the generosity of someone I chat with on Twitter, I was able to get a Google Voice account. I set up the Google Voice account and sent it to my cell phone. I tested it by leaving a voicemail. Sure enough it had emailed a copy of the transcription to Gmail. Next I set up a mail forward to a free mailbox on my ISP. I then configured Getmail to check and remove any messages from my isp. I then set up a Bash script to output the file to a generic name, run sed to edit out everything that is not text, create a variable exectweet="`cat tweet`" , and insert the variable into the status portion of the curl post, delete any messages in the inbox (rm ~/inbox/*), sleep for two minutes, and then check for messages and repeat. The reason for sleeping two minutes is to allow Google Voice enough time to transcribe the message and Gmail to forward the message to my ISP mail. It worked. Sort of.

There was no flaw in my aggregation or editing in the script. This part worked as expected. The let down came with the accuracy of Google Voice. It isn't. You can view two days worth of weird status updates at my test account After those last two messages came through clean, I connected the script to my POTUSCamacho account and threw caution to the wind. I tweeted blind every once in a while. I did not check the accuracy of the messages. When I got home and checked them, they ranged from close but not quite to way off base. I have since "mothballed" any further research into using this as a way to tweet for the time being. Some things are too good to be true sometimes.

I would like to quickly cover some auto status update work I have done on Twitter that runs the status posts of To do this I need to tangent for just a second to two simpler projects I have on Twitter. They are and Cl0ckbot was just a simple bot to see if I could throw one together quickly. I actually keep it running because it serves as nice time hash marks for checking Twitter via the web. I decided to make baitbot to see how much spam I could catch with a simple bot. Baitbot repeats a set of ten different programmed responses on rotation for forty minutes of every hour (This is done to stay below the API limit of 1000 tweets a day which works out to be 41.6 possible every hour). The responses are absurd comments with a popular word or two sprinkled in and a warning message not to follow it. What is interesting about the bot is it repeats the exact same message (sort of) more than once a day (which Twitter will allow you to do). The trick to this is in this line of a status variable in the baitbot script: `date +%S%M` For those that don't know, I used that to sprinkle in the seconds and the minutes of the current hour allowing for a changing two digit number, that does not repeat in a day, in every status message. It makes it "different" as far as Twitter is concerned. I adapted this technique to make an automated status script to advertise the radio station on twitter. The script runs every five minutes of every hour. I did not want it to post constantly, just enough to make it hit in a search for the @public_timeline.

I am going to wrap up the series in saying that I will continue to improve upon my scripts and the overall quality of the radio station portion of the project. If you have comments and suggestions pleased find me on Twitter. If I have interested you, I suggest taking a look at the Twitter API. It really is so easy a cave man could do it.

Stay tuned for more projects and musings.

Wednesday, December 9, 2009

Audio based interfaces for Twitter Part 2

After I came up with the idea of creating a radio station from an audio stream of, I started working on a solution to make it work. First thing I need was a free hosting service. I didn't really expect to find anything, but lo and behold I found two immediately. After some consideration, I decided to go with They support Shoutcast streaming and their site is ad supported with an option for a premium account.

Now with a host in mind and a format, I now had to figure out how to make my scripts work with a Shoutcast source client. I went ahead and used the Nullsoft sc_trans binary since I was familiar with it. My first thought of playing the audio from my server and have sc_trans pick it up via /dev/dsp failed miserably. The sc_trans binary is older than dirt at this point, and on Ubuntu Server 8.04.2 sc_trans would lock up when /dev/sdp was set as the source. Then I got another idea. I decided to add a step in the script that would convert the wav to mp3 using LAME. This added a marginal processing time of of approximatly 2 secs on average per RSS pulled. The total processing time now was up to about four to six seconds. Throwing Shoutcast into the mix did change things though. With the bluetooth system, once a wav file had reached the end, it would disconnect audio from the headset and then repeat the cycle. The Shoutcast source streamer is going to stream the audio based on a playlist. In the playlist configuration, it is not designed for a live feed and I can't capture /dev/dsp. Since this is Linux we are talking about it ended up not really being a problem. The aggregation and audio converstion script will ouput an mp3 with a single filename. sc_trans can be playing that file and if overwritten, the new audio immediatly begins playing. It's a hack for sure, but it doesn't sound bad. The aggregation script had to be changed to run every minute and sleep since there would be nothing to make it pause in the course of the script.

Once everything was in place I tested it. It worked as well as expected. I let it run for a while to see how long it would stay up. The answer was about a day or two. Reasons varied from sc_trans having a segmentation fault to full system lockup. Occasionally sc_trans would be fine. The aggregation and conversion script would be running, but the stream from the net would be silent. One reboot everyday or two would be a short term solution till a better system was devised, but that was a problem. I have a virtual machine on that server that hosts some services for an expiremental IPV6 overlay network. Some of the services in that virutal machine have to be brought up manually. This made doing this a chore. My answer was to setup a speprate VM for the radio station broadcasting software. Now all that is done in a Ubuntu 9.04 server running in VirtualBox. Cron was rebooting the VirtualBox server 4 times a day until a few days ago when I set it for 12 am and 12 pm. It takes approxiamly 2 minutes from reboot to audio. Occasionally I am getting unknown Shoutcast server disconnects, but after reading logs I think it is my stream host shutting down it's end due to an error caused at the host. The station's twitter page is here: The link will take you to the audio streams page.

In "Audio based interfaces for Twitter Part 3" I will cover the mechanisms for advertising the service so that it is picked up in the public timeline and my attempt to use Google Voice transcription as a speech to text conversion tool.

Monday, December 7, 2009

Audio based interfaces for Twitter Part 1

Back in July I decided to join Twitter. My main motivation for joining is that I hate sms messaging and most of my friends prefer to communicate that way. I figured it would be a happy medium for communication. Since then I have found that Twitter is useful for all kinds of things.

For those that don't know, Twitter's API is well documented and can be interfaced with extremly easily. Most feeds on Twitter can be pulled in RSS format, and that gave me an idea. I decided to make an audio interface for my feed. To accomplish this I made a Bash script that does the following: Curl requests my #).rss and saves it to a file. Next I use sed to strip any unnecessary data from the file such as HTML or XML code etc. Once the file is edited, I use a text to speech program called espeak to convert the text to a wav file. Lastly the wav file is played by mplayer and ouput to a bluetooth headset via the alsa bluetooth option.

The script was set up to sleep for fifteen minutes, convert the data, and then run again. It worked as I had planned. After about a week I had another idea. I realized that RSS feed could be converted in the same fashion. So I did. This time I had to modify some things.

I copied the origianl script and modified it. The first modification I made was to have this script run for fifteen minutes then sleep. This basically filled the silent gap the Home script left. The second was something that I made shortly after listening to the audio. Things like " as pure text show up as decimal notated Unicode, so anything that is not readable text gets filtered. Eventually I made the same edit to my original Home audio generating script. The only other edit to this new script was the credentials asking for the data (made a test account) and the url to the RSS data which is: , and lastly changed the filenames that espeak, sed, and curl output.

Now pleased with my bizarre creation I began telling people about it. With this I ran into a problem. It was really hard to explain it to someone face to face, but it was even harder explaining it in 140 characters. After a couple months I got another idea. I was going to broadcast the audio via an online radio station.

In "Audio based interfaces for Twitter Part 2", I will talk about the the things needed to make the radio station work, and some of the on going difficulties I still have. If you want to go ahead and preview the audio then click here If the station is down for some reason, try again latter as I am still working out some issues.