Created
April 11, 2022 15:05
-
-
Save matoken/45d0beada328bd4afa8f58e28a97fc2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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