mathiasbynens/dotfiles — Issue #31: `gsay` function (use Google’s Translate API to say things)
Author: mathiasbynens
Created: 2011-12-12 23:28:55+00:00
State: open

```bash
function gsay { local lang=nl str="$*" tmp="/tmp/gsay.$$.mp3" i=0 line; [ -t 0 ] || str="$(cat)"; fmt -w 100 <<< "$str" | while read -r line; do url="http://translate.google.com/translate_tts?ie=UTF-8&tl=$lang&q=${line//&/%26}"; url="${url// /+}"; curl -sH 'User-Agent: Notabot' "$url" >| "$tmp" && afplay "$tmp"; done; rm -f "$tmp"; }
```