Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Created June 2, 2023 07:31
Show Gist options
  • Save coderofsalvation/17332183979edd40f4474c9d85f211f1 to your computer and use it in GitHub Desktop.
Save coderofsalvation/17332183979edd40f4474c9d85f211f1 to your computer and use it in GitHub Desktop.
simple portable text to speech using ffmpeg or ffplay
#!/bin/sh
# usage: say hello # plays audio (ffplay)
# OUTPUT=/tmp/hello.wav say hello # saves wav (ffmpeg)
dbus_session_file=~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0
if [ -e "$dbus_session_file" ]; then
. "$dbus_session_file"
export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
fi
# set environment when run in cron on xfce4
{ which xfce4-session && eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME xfce4-session)/environ)"; } &>/dev/null
voice=slt
opts="-autoexit -nodisp"
cmd=ffplay
test -z $OUTPUT || { cmd=ffmpeg; opts=""; }
echo "[.] voices: $( ffplay -f lavfi -i flite=list_voices=true 2>&1 | grep _flite | sed 's/.*\]/ /g' | awk '{ printf($0)", " }' )"
${cmd} ${opts} -f lavfi -i flite=text="'$*'":v=$voice -af "flanger,haas=left_delay=20,crystalizer" $OUTPUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment