Skip to content

Instantly share code, notes, and snippets.

@tomriley
Created March 9, 2010 22:55

Revisions

  1. tomriley created this gist Mar 9, 2010.
    21 changes: 21 additions & 0 deletions google-dictionary-text-to-speech.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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