Skip to content

Instantly share code, notes, and snippets.

@tomriley
Created March 9, 2010 22:55
Show Gist options
  • Save tomriley/327253 to your computer and use it in GitHub Desktop.
Save tomriley/327253 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'hpricot'
require 'open-uri'
phrase = "Welcome too mountain view"
mp3s = []
phrase.split(' ').each do |word|
doc = Hpricot(open("http://www.google.com/dictionary?aq=f&langpair=en%7Cen&hl=en&q=#{word}"))
a = doc.search('#pronunciation a')[0]
if a
href = a.attributes['href']
`curl -qO #{href}`
mp3s << href.split('/').last
end
end
mp3s.each do |mp3|
`afplay #{mp3}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment