sapo/sapo-fix.sh

70 lines
3.5 KiB
Bash
Raw Normal View History

2022-03-08 13:15:49 +00:00
#!/bin/bash
2022-03-08 13:22:46 +00:00
#┏━┓┏━┓┏━┓┏━┓ ┏━╸╻╻ ╻
#┗━┓┣━┫┣━┛┃ ┃╺━╸┣╸ ┃┏╋┛
#┗━┛╹ ╹╹ ┗━┛ ╹ ╹╹ ╹
# a tts bash script by Christos Angelopoulos, February 2022
#Attempts to fix errors in wav files generated by sapo.sh (txt to wav)
#using the all powerful https://github.com/coqui-ai/TTS
2022-03-08 13:15:49 +00:00
FILE="$(yad --file-selection --filename=Desktop --height='400' --width='800' --title='Sapo-fix' --window-icon=$HOME/git/sapo/sapo-fix.png --hscroll-policy=never --vscroll-policy=never)"
case $? in
0)
;;
1) exit
;;
esac
DIRECTORY=${FILE%/*}/
NAME=${FILE##*/}
####### FIXING ERRORS ONE BY ONE ############
TOTAL_ERRORS=$(cat "$DIRECTORY""Sapo_""$NAME"/errors.tsv|wc -l)
ERROR_LINE=1
while [ $ERROR_LINE -le $TOTAL_ERRORS ]
do
CURRENT_ERROR_LINE=$(cat "$DIRECTORY""Sapo_""$NAME"/errors.tsv|head -$ERROR_LINE|tail +$ERROR_LINE)
ERROR_TEXT_LINE=$(echo $CURRENT_ERROR_LINE|awk '{print $1}')
ERROR_WAV=$(echo $CURRENT_ERROR_LINE|awk '{print $2}')
TEXT_TO_CORRECT="$(cat "$DIRECTORY""Sapo_""$NAME"/"$NAME"sentenced.txt|head -$ERROR_TEXT_LINE|tail +$ERROR_TEXT_LINE)"
GO=false
while [[ $GO == false ]]
do
2022-03-09 11:04:13 +00:00
yad --image "$HOME/git/sapo/sapo.png" \
2022-03-08 13:15:49 +00:00
--height=40 --width=400 \
2022-03-09 11:04:13 +00:00
--title="Line $ERROR_TEXT_LINE - $NAME" \
2022-03-08 13:15:49 +00:00
--button=gtk-cancel:1 \
--button='▶Play Audio':2 \
2022-03-09 13:18:41 +00:00
--button='🔃Re-Render':3 \
2022-03-09 01:45:12 +00:00
--button='✂Trim Clutter':4 \
2022-03-09 13:18:41 +00:00
--button='🗡Split-Render':5 \
2022-03-08 13:15:49 +00:00
--button='🎵Edit audio':7 \
--button='❌Remove audio':6 \
2022-03-09 11:04:13 +00:00
--button='😃Keep':0 \
2022-03-08 13:15:49 +00:00
--text="Text of line $ERROR_TEXT_LINE :
2022-03-09 11:04:13 +00:00
$TEXT_TO_CORRECT
2022-03-08 13:15:49 +00:00
2022-03-09 11:04:13 +00:00
-What would you like to do?" \
2022-03-09 12:25:41 +00:00
--window-icon=$HOME/git/sapo/sapo-fix.png
2022-03-08 13:15:49 +00:00
case $? in
0) GO=true
;;
1) exit
;;
2) celluloid "$DIRECTORY""Sapo_""$NAME"/$ERROR_WAV
;;
3) s="$(yad --entry --text="This is the original text of the line $ERROR_TEXT_LINE.
Edit as you wish, then hit OK to render." --entry-text="$TEXT_TO_CORRECT" --entry-label="Line:" --window-icon=$HOME/git/sapo/sapo-fix.png --title="${NAME} - Sapo")";tts --text "$s" --out_path "$DIRECTORY""Sapo_""$NAME"/$ERROR_WAV
;;
4)sox -V3 "$DIRECTORY""Sapo_""$NAME"/$ERROR_WAV "$DIRECTORY""Sapo_""$NAME"/temp.wav silence 1 0.50 0.1% 1 0.5 0.1%;sox "$DIRECTORY""Sapo_""$NAME"/temp.wav "$DIRECTORY""Sapo_""$NAME"/$ERROR_WAV pad 0 0.5;rm "$DIRECTORY""Sapo_""$NAME"/temp.wav
;;
5)s="$(yad --entry --text="Split the printed text roughly in half with the pipe symbol (|), so that it can be rendered in two batches: " --entry-text="$TEXT_TO_CORRECT" --entry-label="Line:" --window-icon=$HOME/git/sapo/sapo-fix.png --title="${NAME} - Sapo")";s1="$(echo $s|sed 's/|.*$//')";s2="$(echo $s|sed 's/^.*|//')"; echo $s1;echo $s2 ; tts --text "$s1" --out_path "$DIRECTORY""Sapo_""$NAME"/1temp.wav; tts --text "$s2" --out_path "$DIRECTORY""Sapo_""$NAME"/2temp.wav;sox "$DIRECTORY""Sapo_""$NAME"/1temp.wav "$DIRECTORY""Sapo_""$NAME"/2temp.wav "$DIRECTORY""Sapo_""$NAME"/$ERROR_WAV ; rm "$DIRECTORY""Sapo_""$NAME"/1temp.wav "$DIRECTORY""Sapo_""$NAME"/2temp.wav
;;
6) rm "$DIRECTORY""Sapo_""$NAME"/$ERROR_WAV
;;
7)audacity "$DIRECTORY""Sapo_""$NAME"/$ERROR_WAV
;;
esac
done
((ERROR_LINE++))
done
sox "$DIRECTORY""Sapo_""$NAME"/*.wav "$DIRECTORY""Sapo_""$NAME"/"$NAME".wav
yad --image "$HOME/git/sapo/sapo-fix.png" --height=40 --width=400 --title="${NAME} - Sapo" --text="Reading of ""$NAME"" is complete!" --window-icon=$HOME/git/sapo/sapo-fix.png