#!/bin/sh
#ttsTXT.sh TNM01-01 155
NAME=$1
RATE=$2
[ "$RATE" = "" ] && RATE=155
cmd="say -v Yuna -r $RATE -o $NAME.aiff -f $NAME.txt"
echo $cmd #eval $cmd
cmd="lame -m s $NAME.aiff $NAME.mp3"
echo $cmd #eval $cmd
MF=$2; N=0; FS="";
sed -e $'s/[.] */\\\n/g' $NAME.txt > ${NAME}_tts.txt
while read line; do
L=${line//[[":space:"]]/}
if [ ! -z "$L" ]; then
echo $L
N=$((N+1))
SN=$( printf "%05d" $N )
cmd="say -v Yuna -r $RATE -o $NAME-$SN.aiff \"$L\""
echo $cmd; eval $cmd;
fi
done < ${NAME}_tts.txt
N=0
#find $NAME*.aiff -type f -print0 | xargs -0 ls -tr | while read file; do
# N=$((N+1))
# new=$( printf "%05d.%s" $N "${file##*.}" )
# mv "$file" "$new"
#done
N=0; FS=""; MF="$NAME-all.aiff"; MAP=""; GAP=""
for f in $NAME*.aiff; do
FS="$FS -i \"$f\" "
MAP="${MAP}[${N}][g${N}]"
N=$((N+1))
done
NG=$(($N*2))
G=$(($N-1))
for (( i=0; i<$N; i++ )); do
GAP="${GAP}[$N]atrim=duration=1[g${i}];"
done
cmd="ffmpeg \
$FS \
-f lavfi -i anullsrc \
-filter_complex '${GAP}${MAP}concat=n=$NG:v=0:a=1[a]' -map '[a]' \
$MF"
echo $cmd
eval $cmd