2022-03-08 13:15:49 +00:00
#!/bin/bash
2022-03-22 01:37:47 +00:00
#
# ▗▄▖ ▄▄ █
#▗▛▀▜ ▐▛▀ ▀
2022-03-10 20:00:56 +00:00
#▐▙ ▟██▖▐▙█▙ ▟█▙ ▐███ ██ ▝█ █▘
2022-03-22 01:37:47 +00:00
# ▜█▙ ▘▄▟▌▐▛ ▜▌▐▛ ▜▌ ▐▌ █ ▐█▌
# ▜▌▗█▀▜▌▐▌ ▐▌▐▌ ▐▌ ██▌ ▐▌ █ ▗█▖
#▐▄▄▟▘▐▙▄█▌▐█▄█▘▝█▄█▘ ▐▌ ▗▄█▄▖ ▟▀▙
2022-03-10 20:00:56 +00:00
# ▀▀▘ ▀▀▝▘▐▌▀▘ ▝▀▘ ▝▘ ▝▀▀▀▘▝▀ ▀▘
2022-03-22 01:37:47 +00:00
# ▐▌
#
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) "
2022-03-22 01:37:47 +00:00
case $? in
0)
; ;
2022-03-08 13:15:49 +00:00
1) exit
2022-03-22 01:37:47 +00:00
; ;
2022-03-08 13:15:49 +00:00
esac
DIRECTORY = ${ FILE %/* } /
NAME = ${ FILE ##*/ }
2022-04-03 12:09:26 +00:00
AUDIO_EDITOR = "audacity"
2022-03-22 21:08:56 +00:00
####### FIXING ERRORS ONE BY ONE or EDIT THE FILE LINE BY LINE############
2022-03-27 15:34:17 +00:00
yad --image " $HOME /git/sapo/sapo-fix.png " \
2022-03-22 21:08:56 +00:00
--height= 40 --width= 200 --title= " ${ NAME } - Sapo " \
--text= "Which lines do you want to fix?" \
--button= gtk-cancel:1 \
--button= 'All Lines' :2 \
--button= 'Just Errors' :3 \
2022-03-27 15:34:17 +00:00
--window-icon= $HOME /git/sapo/sapo-fix.png
2022-03-22 21:08:56 +00:00
case $? in
1) exit
; ;
2) LINES_TO_EDIT = "ALL"
; ;
3) LINES_TO_EDIT = "ERRORS"
; ;
esac
if [ [ $LINES_TO_EDIT = = "ALL" ] ]
then
TOTAL_ERRORS = $( cat " $DIRECTORY " "Sapo_" " $NAME " /" $NAME " sentenced.txt| wc -l)
else
TOTAL_ERRORS = $( cat " $DIRECTORY " "Sapo_" " $NAME " /errors.tsv| wc -l)
fi
2022-03-08 13:15:49 +00:00
ERROR_LINE = 1
2022-03-24 00:59:27 +00:00
BROWSE_NEXT = false
2022-03-08 13:15:49 +00:00
while [ $ERROR_LINE -le $TOTAL_ERRORS ]
do
2022-03-22 21:08:56 +00:00
if [ [ $LINES_TO_EDIT = = "ALL" ] ]
then
CURRENT_ERROR_LINE = $ERROR_LINE
ERROR_TEXT_LINE = $ERROR_LINE
else
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}' )
fi
ERROR_WAV = " $( printf "%.6d" $ERROR_TEXT_LINE ) " .wav
2022-03-08 13:15:49 +00:00
TEXT_TO_CORRECT = " $( cat " $DIRECTORY " "Sapo_" " $NAME " /" $NAME " sentenced.txt| head -$ERROR_TEXT_LINE | tail +$ERROR_TEXT_LINE ) "
GO = false
2022-03-22 01:37:47 +00:00
2022-03-08 13:15:49 +00:00
while [ [ $GO = = false ] ]
do
2022-03-24 00:59:27 +00:00
if [ [ $BROWSE_NEXT = = true ] ]
then
2022-03-27 15:34:17 +00:00
killall mplayer; mplayer " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV &
2022-03-24 00:59:27 +00:00
fi
BROWSE_NEXT = false
2022-04-03 21:00:08 +00:00
DURATION = $( sox " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV -n stat 2>& 1 | grep "Length" | sed 's/^.*\: *//;s/....$//' )
2022-04-03 12:09:26 +00:00
yad --image " $HOME /git/sapo/sapo.png " \
2022-03-08 13:15:49 +00:00
--height= 40 --width= 400 \
2022-03-22 23:10:34 +00:00
--title= " Line $ERROR_TEXT_LINE ( of $TOTAL_ERRORS )- $NAME " \
2022-03-08 13:15:49 +00:00
--button= gtk-cancel:1 \
2022-03-27 15:34:17 +00:00
--button= '▶️ Play' :2 \
2022-04-01 21:01:08 +00:00
--button= '🔃 Render' :3 \
2022-03-27 15:34:17 +00:00
--button= '✂️ Trim' :4 \
2022-04-01 21:01:08 +00:00
--button= '🪚 Split' :5 \
--button= '🛠️ Edit' :7 \
2022-03-27 15:34:17 +00:00
--button= '❌ Remove' :6 \
--button= '⬅️ Previous' :8 \
--button= '➡️ Next' :0 \
--button= '👉 Go To' :10 \
2022-04-01 21:01:08 +00:00
--button= '⏩ Browse' :9 \
2022-04-03 12:09:26 +00:00
--text= " -Text of line $ERROR_TEXT_LINE ( of $TOTAL_ERRORS ):
2022-03-22 01:37:47 +00:00
<span foreground = 'yellow' ><b>$TEXT_TO_CORRECT </b></span>
2022-04-03 12:09:26 +00:00
-Duration : <span foreground = 'orange' ><b>$DURATION </b></span> sec
2022-03-09 11:04:13 +00:00
-What would you like to do ?" \
2022-04-03 12:09:26 +00:00
--window-icon= $HOME /git/sapo/sapo.png
2022-03-22 01:37:47 +00:00
case $? in
2022-03-27 15:34:17 +00:00
0) killall mplayer; GO = true
2022-03-22 01:37:47 +00:00
; ;
2022-03-08 13:15:49 +00:00
1) exit
; ;
2022-03-27 15:34:17 +00:00
2) if [ [ -e " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV ] ] ; then killall mplayer; mplayer " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV & else notify-send "There is no file " " $DIRECTORY " "Sapo_" " $NAME " /" $ERROR_WAV " "." ; fi
2022-03-22 01:37:47 +00:00
; ;
2022-03-27 15:34:17 +00:00
3) killall mplayer; s = " $( yad --entry --width= "600" --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 " --window-icon= $HOME /git/sapo/sapo-fix.png --title= " Line $ERROR_TEXT_LINE - $NAME ")" ; tts --text " $s " --out_path " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV
2022-03-08 13:15:49 +00:00
; ;
2022-03-27 15:34:17 +00:00
4) killall mplayer; 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
2022-03-08 13:15:49 +00:00
; ;
2022-03-27 15:34:17 +00:00
5) killall mplayer; s = " $( yad --entry --width= "600" --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 " --window-icon= $HOME /git/sapo/sapo-fix.png --title= " Line $ERROR_TEXT_LINE - $NAME " ) " ; 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
2022-03-22 01:37:47 +00:00
; ;
2022-03-27 15:34:17 +00:00
6) killall mplayer; if [ [ -e " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV ] ] ; then rm " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV ; notify-send " $DIRECTORY " "Sapo_" " $NAME " /" $ERROR_WAV " " has been deleted." ; else notify-send "There is no file " " $DIRECTORY " "Sapo_" " $NAME " /" $ERROR_WAV " ". Already deleted?" ; fi ; GO = true
2022-03-08 13:15:49 +00:00
; ;
2022-04-03 12:09:26 +00:00
7) killall mplayer; $AUDIO_EDITOR " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV
2022-03-08 13:15:49 +00:00
; ;
2022-03-27 15:34:17 +00:00
8) killall mplayer; GO = true; ERROR_LINE = $(( $ERROR_LINE - 2 ))
2022-03-24 00:59:27 +00:00
; ;
2022-03-27 15:34:17 +00:00
9) killall mplayer; BROWSE_NEXT = true; GO = true
2022-03-24 00:59:27 +00:00
; ;
2022-03-27 15:34:17 +00:00
10) killall mplayer; ERROR_LINE = " $( yad --entry --height= 40 --width= 400 --text= "Go To Line:" --entry-text= " $ERROR_LINE " --window-icon= $HOME /git/sapo/sapo-fix.png --title= "Go To Line " ) " ; ( ( ERROR_LINE--) ) ; GO = true
2022-03-08 13:15:49 +00:00
esac
done
( ( ERROR_LINE++) )
done
sox " $DIRECTORY " "Sapo_" " $NAME " /*.wav " $DIRECTORY " "Sapo_" " $NAME " /" $NAME " .wav
2022-03-27 15:34:17 +00:00
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