sapo/Sapo.sh

144 lines
5.8 KiB
Bash
Raw Normal View History

2022-03-04 23:44:45 +00:00
#! /bin/bash
#┏━┓┏━┓┏━┓┏━┓
#┗━┓┣━┫┣━┛┃ ┃
#┗━┛╹ ╹╹ ┗━┛
# a tts bash script by Christos Angelopoulos, February 2022
#converts txt to wav
#using the all powerful https://github.com/coqui-ai/TTS
2022-03-05 16:26:12 +00:00
FILE="$(yad --file-selection --filename=Desktop --height='400' --width='800' --title='Sapo - Select File to Read' --window-icon=$HOME/git/sapo/sapo.png --hscroll-policy=never --vscroll-policy=never)"
2022-03-04 23:44:45 +00:00
case $? in
0)
;;
1) exit
;;
esac
DIRECTORY=${FILE%/*}/
NAME=${FILE##*/}
echo "FILE : ""$FILE"
echo "DIRECTORY : " "$DIRECTORY"
echo "NAME : ""$NAME"
mkdir "$DIRECTORY""Sapo_""$NAME"/
##text delimitation to setences
echo $(cat "$FILE")>"$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt # get rid of new lines
sed -i 's/\./\.\n/g' "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt # delimit to .
sed -i 's/\!/\!\n/g' "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt # delimit to !
sed -i 's/\?/\?\n/g' "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt # delimit to ?
sed -i 's/\:/\:\n/g' "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt # delimit to :
sed -i 's/\;/\;\n/g' "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt # delimit to ;
2022-03-06 18:34:52 +00:00
#sed -i 's/\(/\(\n/g' "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt # delimit to (
#sed -i 's/\)/\)\n/g' "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt # delimit to )
2022-03-04 23:44:45 +00:00
sed -i 's/^ //g' "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt # delete space at beginning of line
sed -i 's/^\;$//g' "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt # get rid of just ; lines
sed -i 's/^\!$//g' "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt # get rid of just ; lines
#sed -i 's/\,/\n/3' "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt # delimit to 3rd occurence of ,
##alphabet substitutions
2022-03-05 11:27:03 +00:00
sed -i -f $HOME/git/sapo/sapofonetix.sed "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt
2022-03-04 23:44:45 +00:00
2022-03-05 11:27:03 +00:00
#done < "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt
2022-03-04 23:44:45 +00:00
##################extra delimit to comma and space ###################################
2022-03-06 12:42:36 +00:00
DELIM=$(cat "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt|wc -l)
while [ $DELIM -ge 1 ]
2022-03-04 23:44:45 +00:00
do
2022-03-06 12:42:36 +00:00
CUR_DELIM_LINE=$(cat "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt|head -$DELIM|tail +$DELIM)
CHAR_COUNT=$(echo "$CUR_DELIM_LINE"|wc -m)
while [ $CHAR_COUNT -gt 290 ]
2022-03-04 23:44:45 +00:00
do
2022-03-06 12:42:36 +00:00
echo "character count : "$CHAR_COUNT
echo "characters > 290"
COMMA_COUNT=$(echo "$CUR_DELIM_LINE"| sed -e 's/\(.\)/\1\n/g' | grep "," | wc -l)
echo "comma count : "$COMMA_COUNT
if [ $COMMA_COUNT -gt 2 ]
then
echo "commas > 2"
echo $DELIM"s/\,/\n/"$(($COMMA_COUNT - 2))>"$DIRECTORY""Sapo_""$NAME"/script.sed
sed -i -f "$DIRECTORY""Sapo_""$NAME"/script.sed "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt
fi
if [ $COMMA_COUNT -le 2 ]
then
echo "No commas to delimit to, proceed delimiting with spaces(limit 30)"
SPACE_COUNT=$(echo "$CUR_DELIM_LINE"| sed -e 's/\(.\)/\1\n/g' | grep " " | wc -l)
echo "Space count : "$SPACE_COUNT
echo $DELIM"s/\ /\n/"$(($SPACE_COUNT - 30))>"$DIRECTORY""Sapo_""$NAME"/script.sed
sed -i -f "$DIRECTORY""Sapo_""$NAME"/script.sed "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt
fi
2022-03-05 22:14:26 +00:00
CUR_DELIM_LINE=$(cat "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt|head -$DELIM|tail +$DELIM)
2022-03-04 23:44:45 +00:00
CHAR_COUNT=$(echo "$CUR_DELIM_LINE"|wc -m)
2022-03-06 12:42:36 +00:00
2022-03-04 23:44:45 +00:00
done
2022-03-06 12:42:36 +00:00
echo "Task completed for line "$DELIM
((DELIM--))
2022-03-04 23:44:45 +00:00
done
2022-03-06 12:42:36 +00:00
2022-03-05 16:26:12 +00:00
yad --image "$HOME/git/sapo/sapo.png" --height=40 --width=400 --title="${NAME} - Sapo" --button=gtk-cancel:1 --button=gtk-ok:0 --button=gtk-open:2 --text="The text is prepared, for further editing open: $DIRECTORY\Sapo$NAME/$NAME\sentenced.txt, and press OK to proceed to speech conversion." --window-icon=$HOME/git/sapo/sapo.png
2022-03-04 23:44:45 +00:00
case $? in
0)
;;
1) exit
;;
2022-03-05 22:14:26 +00:00
2) xed "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt & yad --image "$HOME/git/sapo/sapo.png" --height=40 --width=400 --title="${NAME} - Sapo" --button=gtk-cancel:1 --button=gtk-ok:0 --text="If you are done editing $DIRECTORY\Sapo$NAME/$NAME\sentenced.txt, press OK to continue!" --window-icon=$HOME/git/sapo/sapo.png
2022-03-05 16:26:12 +00:00
case $? in
0)
;;
1) exit
;;
esac
2022-03-04 23:44:45 +00:00
esac
TOTALLINES=$(cat "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt|wc -l)
LINE=1
(
while [ $LINE -le $TOTALLINES ]
do
CURRENTLINE=$(head -$LINE "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt|tail +$LINE)
FORMLINE="$(printf "%.6d" $LINE)"
CURRENTLINEURI="$(echo "$CURRENTLINE" | jq -s -R -r @uri)"
tts --text "$CURRENTLINE" --out_path "$DIRECTORY""Sapo_""$NAME"/$FORMLINE.wav
LINE100=$(( $LINE * 100 ))
PERCENTAGE=$(( $LINE100 / $TOTALLINES))
###Estimating Estimated time of arrival
LINESLEFT=$(( $TOTALLINES - $LINE ))
SECONDS=$(( $LINESLEFT * 8 ))
HOURS=$(( SECONDS / 3600 ))
SECHLEFT=$(( $SECONDS - $((HOURS * 3600 )) ))
MINUTES=$(( $SECHLEFT / 60 ))
SECMLEFT=$(( $SECHLEFT - $((MINUTES * 60 )) ))
HOURSTRING="$HOURS"" hrs"
MINUTESTRING="$MINUTES"" mins"
## if hours / minutes left are 0 , they are not mentioned
if [ $HOURS -eq 0 ]
then
HOURSTRING=""
fi
if [ $MINUTES -eq 0 ]
then
MINUTESTRING=""
fi
2022-03-05 11:27:03 +00:00
#echo line starting with #, updated in the yad progress bar window
2022-03-04 23:44:45 +00:00
echo "# Reading line $(( $LINE + 1)) of $TOTALLINES from "$NAME" ($PERCENTAGE%). Roughly remaining : "$HOURSTRING" "$MINUTESTRING" " $SECMLEFT" secs"
echo "$PERCENTAGE"
((LINE++))
done
) |
2022-03-05 11:27:03 +00:00
yad --progress --height="40" --width="400" \
2022-03-06 12:42:36 +00:00
--title="Sapo - Reading . . . ${NAME}" \
2022-03-04 23:44:45 +00:00
--percentage=0 \
--height=40 \
--width=500 \
2022-03-05 16:26:12 +00:00
--window-icon=$HOME/git/sapo/sapo.png \
2022-03-06 12:42:36 +00:00
--image "$HOME/git/sapo/sapo_progress.png" \
2022-03-05 11:27:03 +00:00
--auto-close
#--text="Preparing to read..." \
2022-03-04 23:44:45 +00:00
case $? in
0)
;;
1) exit
;;
esac
sox "$DIRECTORY""Sapo_""$NAME"/*.wav "$DIRECTORY""Sapo_""$NAME"/"$NAME".wav
2022-03-05 16:26:12 +00:00
yad --image "$HOME/git/sapo/sapo.png" --height=40 --width=400 --title="${NAME} - Sapo" --text="Reading of ""$NAME"" is complete!" --window-icon=$HOME/git/sapo/sapo.png