Skip to content

Instantly share code, notes, and snippets.

@matoken
Created April 11, 2022 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matoken/45d0beada328bd4afa8f58e28a97fc2d to your computer and use it in GitHub Desktop.
Save matoken/45d0beada328bd4afa8f58e28a97fc2d to your computer and use it in GitHub Desktop.
#!/bin/bash
COMMANDS=(nkf curl)
for COMMAND in "${COMMANDS[@]}"
do
type "${COMMAND}" > /dev/null 2>&1 || {
echo "${COMMAND} are required." 1>&2
exit 1
}
done
nc -w 1 -v 127.0.0.1 50021 < /dev/null > /dev/null 2>&1 || {
echo "can't connect VOICEVOX ENGINE."
exit 1
}
if [ $# == 0 ]; then
echo "$0 TEXT [SPEAKER]"
exit
fi
text=$(echo "$1" | nkf -WwMQ | sed 's/=$//g' | tr "=" "%" | tr -d '\n')
body="$(curl -s -X 'POST' -d '' -H 'accept: application/json' "http://127.0.0.1:50021/audio_query?text=$text&speaker=${2}")"
curl -s -X 'POST' "http://127.0.0.1:50021/synthesis?speaker=${2:-0}" -H 'accept: audio/wav' -H 'Content-Type: application/json' -d "$body" || {
echo audio output error. 1>&2
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment