Skip to content

Instantly share code, notes, and snippets.

@naoki-mizuno
Last active December 16, 2017 19:37
Show Gist options
  • Save naoki-mizuno/a4afd293327e662c4b835854cf371a2a to your computer and use it in GitHub Desktop.
Save naoki-mizuno/a4afd293327e662c4b835854cf371a2a to your computer and use it in GitHub Desktop.
#!/bin/bash
DIALOGUE=''
TONE='neutral'
while getopts 'hf:t:' flag; do
case "$flag" in
f)
DIALOGUE=$OPTARG
;;
t)
TONE=$OPTARG
;;
h)
echo "Usage:"
echo " $0 [-h] [-t <happy|neutral|angry|sad> <file>"
exit 0
esac
done
shift $(( $OPTIND - 1 ))
SENTENCE="$1"
VOICE_FILE=tohoku-f01-${TONE}.htsvoice
VOICE_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/open_jtalk/tohoku-f01"
VOICE_URL="https://github.com/icn-lab/htsvoice-tohoku-f01/raw/master/$VOICE_FILE"
if ! [[ -f $VOICE_DIR/$VOICE_FILE ]]; then
mkdir -p $VOICE_DIR
echo -n "Downloading $TONE voice..."
wget -q $VOICE_URL -O $VOICE_DIR/$VOICE_FILE
echo "done!"
fi
if [ -p /dev/stdin ] || [ "$SENTENCE" = '-' ]; then
TMP_IN="$( mktemp )"
DIALOGUE="$TMP_IN"
cat > $TMP_IN
elif [ -z "$DIALOGUE" ]; then
TMP_IN="$( mktemp )"
echo "$SENTENCE" > "$TMP_IN"
DIALOGUE="$TMP_IN"
fi
TMP="$( mktemp )"
open_jtalk -m "$VOICE_DIR/$VOICE_FILE" \
-x ~/usr/dic \
-ow "$TMP" \
"$DIALOGUE"
aplay --quiet "$TMP"
rm "$TMP"
if [ -n "$TMP_IN" ]; then
rm "$TMP_IN"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment