An apple script for google dictionary pronunciation

applescriptaudioautomatordictionarygoogle

The following is the link to Goole dictionary pronunciation files:

http://ssl.gstatic.com/dictionary/static/sounds/20160317/pronunciation–_us_1.mp3

If you substitute "pronunciation" with your own word, you get that word's pronunciation.

I wonder if it is possible to develop a script in mac which allows the user to type his word and the script fetches its pronunciation through the above link. I can already use the automator to fetch the definition for a new word (by using the code presented here) through the link below by adding words after the equal sign.

https://www.google.com/search?sa=X&biw=1440&bih=737&q=Dictionary#dobs=

But I don't know how I can insert words in the mentioned place in the pronunciation link.

Best Answer

In bash, it's very easy:

cd ~/Desktop; curl --remote-name-all --silent --url \
http://ssl.gstatic.com/dictionary/static/sounds/20160317/\
{wrought,drought,rough,thorough}--_us_1.mp3

That will download the files for wrought, drought, rough, and thorough, and save them on the desktop.

If you want to put it in an AppleScript:

    set word_list to {"wrought", "drought", "rough", "thorough"}

    set my text item delimiters to ","
    set my text item delimiters to {word_list as text, "{word-list}"}

    set curl to "cd ~/Desktop; curl --remote-name-all --silent --url " & ¬
        "http://ssl.gstatic.com/dictionary/static/sounds/20160317/" & ¬
        "{{word-list}}--_us_1.mp3"

    text items of curl as text

    do shell script the result

To obtain user input to allow a user to supply a word to feed into the URL, replace the first line with these two:

    display dialog "Enter a word:" default answer "pronunciation"
    set word_list to {text returned} of the result