Thursday, March 5, 2009

I've Been Programming

I haven't posted much lately, mostly because I've been tightly focused on a computer programming project. Let's just say that programming is easily as jealous a consort of one's time as blogging.

I've programmed personal computers ever since my first Radio Shack TRS-80 Model I back in 1976. I got my first Apple II a year later, and have stayed in the Apple fold ever since. Since 1976, I've programmed in Basic, Fortran, assembly language, several machine languages, Pascal, Python, S, R, C, Perl and a few others.

For the past few years, I've been closely eyeing Ruby, a relatively new language, but haven't had the right incentive to dive into it. However, there's nothing like building a cool, new project to learn a new language.

I've spent much of my academic time in the past two weeks writing a web-based text-to-speech application in Ruby. My goal: type in the volume, issue and page number of some article in a major radiology journal and get back an .mp3 version of that article, read by a fairly decent computerized voice.

It turned out to be a lot easier than I thought it would be, even with a few years of web-apps under my belt. Ruby is a fine language, with a fine library of built-in tools, making it easy to scrape a whole web page with just a few lines of Ruby code. For example, the following code is all that's necessary to grab a whole article from the American Journal of Roentgenology and assign it to the variable ajr_html:
urlRaw = ""
+ ajrVolume +"/" + ajrIssue + "/" + ajrPage
ajr_url = open(urlRaw)
ajr_html =
I have recently become a big fan of text-to-speech conversion. In December, I discovered a new Mac program called Textcast. Since then, I've used Textcast to make one or two hundred podcasts for my iPhone from NY Times articles and various blogs I follow. These have been a major defense against boredom during my work commutes -- sort of like having an NPR station where all the stories are interesting.

The only issue I have with Textcast is that it is optimized only for pages from Safari or NetNewsWire. If I want to use it to grab and convert an article from AJR or Radiology, I need to first do some serious hand-scrubbing of the text from their websites before I can feed it into Textcast. I got pretty tired of this after laundering a few articles by hand. My new Ruby script takes virtually all of the drudgery out of this process.

Now that I've refined my program into a reasonably stable version, I've asked several of my residents, fellows and fellow faculty to do some alpha testing. Once I get their feedback, I'll write it up for one of our radiology journals. Might as well get some academic mileage out of it.


halfmd said...

Similar to you, I use text-to-speech on a regular basis. I use my Amazon Kindle when I'm driving to read books to me---kind of like a free books-on-tape. It's great for blogs, newspapes, novels. And I agree with your statement about NPR and its lack of interesting content.

l33t MD said...

However, there's nothing like building a cool, new project to learn a new language.

So true! I've been looking for excuses to dive into Ruby (and Python as well), but never seem to find any worthy projects. Wish I had thought of the text-to-speech thing first, that was an awesome idea. :)

You do realize you're giving me some serious competition for the title l33t MD? ;)

The Samurai Radiologist said...

@ halfmd: I don't mean to dis NPR. I love a lot of their content, but find about half of their topics a bit tiresome these days. Guess I've gotten spoiled by creating my own programming. :)

The Samurai Radiologist said...

@ l33t MD: You are very kind. :) I don't think of myself as l33t so much as a one-eyed programmer in the kingdom of computer-blind radiologists .

Our departmental webmaster is a Jedi at PHP/Python, and he gives me a quick reality check anytime I start acting l33ter than thou. When we collaborate on projects, I hand him a giant, ugly, bleeding slab of code that mostly does what I want. He rolls his eyes, sighs, and ends up polishing it up into a jewel that is far beyond my abilities.

Programming is great fun, and a vice I wish I could indulge more often. Taking a few weeks to craft some fun and useful Internet tool beats the hell out of clawing my way to an RO1 grant.

Text-to-speech apps are by no means exhausted by my humble program. There are plenty of other swell apps waiting to be written. Once I get it written up for publication, I'd be happy to share my code with you.