summaryrefslogtreecommitdiffstats
path: root/util/bin/google.text2speech
blob: cd387cc00863ac1c2f5192957b40d1d6ca9aa3b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
set -euf

TL=${TL:="en"}

usage(){
  echo 'TL= can specifiy which language to use, default is "en"'
  echo 'valid languages: https://cloud.google.com/translate/v2/using_rest#language-params'
  echo 'Example: TL="de" ./text2speech.google "whats up?" | mpv -'
  exit 0
}

text2speech(){
  text=$*
  url="http://translate.google.com/translate_tts?ie=UTF-8&tl=$TL"

  curl -A "Mozilla/5.0" -Ss "$url" --data-urlencode "q=$text"
}

if [ $# -eq 0 ]; then
  usage
fi

text2speech $*