树莓派TTS(文本朗读)脚本
大家好!偶然发现树莓派上可以装espeak来朗读文本。
于是写了以下脚本。
#! /bin/sh
# ttsshell.sh: TXT TO SPEACH SHELL SCRIPT
# Version: 2015-03-13
#
[ ! -f /usr/bin/espeak ] && sudo apt-get -y install espeak
red="\033[31;40m"
green="\033[32;40m"
yello="\033[33;40m"
end="\033[m"
speaker=m
lang=en
[ $# -eq 1 ] && speaker=$1
[ $# -eq 2 ] && lang=$2 && speaker=$1
[ $speaker = "f" ] || speaker=m
[ $lang = "zh" ] || lang=en
out=0
while [ $out -eq 0 ]; do
printf "${yello}TTSSHELL: ${red}[$lang][$speaker] > $green"
read -r TXT
echo $TXT >> .ttsshell.history
printf "$end"
if [ $(echo $TXT|grep -c "^speaker") -gt 0 -o $(echo $TXT|grep -c "^lang") -gt 0 ]; then
[ $(echo $TXT|grep -c "^speaker") -gt 0 ] && speaker=$(echo $TXT|awk '{print $2}')
[ $(echo $TXT|grep -c "^lang") -gt 0 ] && lang=$(echo $TXT|awk '{print $2}')
else
if [ $(echo $TXT|grep -c "^quit") -gt 0 -o A"$TXT" = "A" ] ; then
out=1
else
#[ $speaker = "M" ] && echo "$TXT"|festival --tts || espeak -vzh+f3 -k5 -s140 "$TXT" 2>/dev/null
espeak -v${lang}+${speaker}3 -k5 -s140 "$TXT" 2>/dev/null
fi
fi
done
可以输入任何中英文文本,让树莓派替你朗读。
必须赞一个。 挺有趣的东西
页:
[1]