forked from nethesis/nethvoice-it-sounds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_audio_from_google
executable file
·36 lines (30 loc) · 1.12 KB
/
get_audio_from_google
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
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
if [[ -z $GOOGLE_API_KEY ]]; then
echo "configure google api key before. Launch: "
echo "export GOOGLE_API_KEY='your_google_api_key_here'"
exit 1
fi
if [[ ! -z $1 ]] ; then
#extract only $1 file
GREP='^\./'$1'|'
else
GREP='^\./.*|'
fi
#create directories
for dir in core/digits core/dictate core/phonetic core/followme core/letters extra/wx extra/ha; do
mkdir -p $dir
done
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for row in $(grep $GREP text)
do
FILENAME=$(echo $row | cut -d\| -f1)
TEXT=$(echo $row | cut -d\| -f2)
PACKAGE=$(echo $row | cut -d\| -f3 | awk '{print $1}')
if [[ ! -d $PACKAGE ]]; then
mkdir $PACKAGE
fi
curl 'https://texttospeech.googleapis.com/v1/text:synthesize?key='$GOOGLE_API_KEY -H 'Content-Type:application/json' --data '{"input":{"text":"'$(echo $TEXT | sed "s/\([;\"']\)/\\\\\1/g" )'"}, "voice": {"languageCode":"it-IT", "name":"it-IT-Wavenet-A", "ssmlGender":"FEMALE"}, "audioConfig": {"audioEncoding":"LINEAR16"} }' | jq -r '.audioContent' | base64 --decode > $PACKAGE/$FILENAME.sln16
echo -e "$PACKAGE $FILENAME\t$TEXT"
done
IFS=$SAVEIFS