2022-04-21 14:06:35 +00:00
#!/bin/bash
#
2022-04-21 15:21:51 +00:00
# ▗▄▖ ▄▄ █ ▗▄▖ █
#▗▛▀▜ ▐▛▀ ▀ ▝▜▌ ▀
#▐▙ ▟██▖▐▙█▙ ▟█▙ ▐███ ██ ▝█ █▘ ▟██▖ ▐▌ ██
# ▜█▙ ▘▄▟▌▐▛ ▜▌▐▛ ▜▌ ▐▌ █ ▐█▌ ▐▛ ▘ ▐▌ █
# ▜▌▗█▀▜▌▐▌ ▐▌▐▌ ▐▌ ██▌ ▐▌ █ ▗█▖ ██▌ ▐▌ ▐▌ █
#▐▄▄▟▘▐▙▄█▌▐█▄█▘▝█▄█▘ ▐▌ ▗▄█▄▖ ▟▀▙ ▝█▄▄▌ ▐▙▄ ▗▄█▄▖
# ▀▀▘ ▀▀▝▘▐▌▀▘ ▝▀▘ ▝▘ ▝▀▀▀▘▝▀ ▀▘ ▝▀▀ ▀▀ ▝▀▀▀▘
2022-04-21 14:06:35 +00:00
# ▐▌
#
2022-05-05 22:15:32 +00:00
# a tts bash script by Christos Angelopoulos, April 2022
2022-04-21 14:06:35 +00:00
#Attempts to fix errors in wav files generated by sapo.sh (txt to wav)
#using the all powerful https://github.com/coqui-ai/TTS
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 ##*/ } ; NAME = ${ NAME %.* }
AUDIO_EDITOR = "audacity"
####### FIXING ERRORS ONE BY ONE or EDIT THE FILE LINE BY LINE############
2022-04-23 12:19:46 +00:00
echo " ╭────────────────────────────────────────────────────────────────╮
│Select: │
├─┬──────────────────────────────────────────────────────────────┤
│1│ to edit ALL LINES │
├─┼──────────────────────────────────────────────────────────────┤
│2│ to edit only lines with detected errors │
├─┼──────────────────────────────────────────────────────────────┤
│3│ Exit │
╰─┴──────────────────────────────────────────────────────────────╯"
read -p "Select: " C
case $C in
3) exit
; ;
1) LINES_TO_EDIT = "ALL"
2022-04-21 14:06:35 +00:00
; ;
2022-04-23 12:19:46 +00:00
"" ) LINES_TO_EDIT = "ALL"
2022-04-21 14:06:35 +00:00
; ;
2022-04-23 12:19:46 +00:00
2) LINES_TO_EDIT = "ERRORS"
2022-04-21 14:06:35 +00:00
; ;
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
ERROR_LINE = 1
BROWSE_NEXT = false
while [ $ERROR_LINE -le $TOTAL_ERRORS ]
do
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
TEXT_TO_CORRECT = " $( cat " $DIRECTORY " "Sapo_" " $NAME " /" $NAME " sentenced.txt| head -$ERROR_TEXT_LINE | tail +$ERROR_TEXT_LINE ) "
GO = false
2022-04-23 12:19:46 +00:00
Yellow = "\033[1;33m"
bold = ` tput bold`
normal = ` tput sgr0`
2022-04-24 22:50:59 +00:00
italic = "\x1b[3m"
2022-04-21 14:06:35 +00:00
while [ [ $GO = = false ] ]
do
if [ [ $BROWSE_NEXT = = true ] ]
then
killall mplayer > /dev/null 2>& 1 ; mplayer -really-quiet " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV &
fi
BROWSE_NEXT = false
DURATION = $( sox " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV -n stat 2>& 1 | grep "Length" | sed 's/^.*\: *//;s/....$//' )
clear
2022-04-21 15:21:51 +00:00
BOXTEXT = $( echo " $TEXT_TO_CORRECT " | fold -w 78 -s| sed 's/$/ /g' | sed 's/\(^.\{1,78\}\).*/\1/' | sed 's/^/│/g;s/$/│/g' )
2022-04-23 12:19:46 +00:00
BOXDURATION = $( echo " Duration : $DURATION sec " | sed 's/$/ /g' | sed 's/\(^.\{1,38\}\).*/\1/' )
BOXFIRSTLINE = $( echo " Text of line $ERROR_TEXT_LINE ( of $TOTAL_ERRORS ): " | sed 's/$/ /g' | sed 's/\(^.\{1,38\}\).*/\1/' )
2022-05-05 22:15:32 +00:00
echo -e " ╭──────────────────────────────────────╮╭──────────────────────────────────────╮
│$BOXFIRSTLINE ││$BOXDURATION │
╰──────────────────────────────────────╯╰──────────────────────────────────────╯
2022-04-24 22:50:59 +00:00
${ Yellow } ${ italic } ╭──────────────────────────────────────────────────────────────────────────────╮
2022-04-21 14:06:35 +00:00
$BOXTEXT
2022-04-21 15:21:51 +00:00
╰──────────────────────────────────────────────────────────────────────────────╯${ normal }
2022-04-23 12:19:46 +00:00
╭────────────────────────┬──────────────────────────┬──────────────────────────╮
2022-04-25 11:09:23 +00:00
│ 1. ⏩ Browse │ 2. ▶️ Play │ 3. 🔃 Render │
2022-04-21 15:21:51 +00:00
├────────────────────────┼──────────────────────────┼──────────────────────────┤
2022-05-05 22:15:32 +00:00
│ 4. 👉 Go To │ 5. ⬅️ Previous │ 6. ➡️ Next │
2022-04-21 15:21:51 +00:00
├────────────────────────┼──────────────────────────┼──────────────────────────┤
2022-04-25 11:09:23 +00:00
│ 7. ✂️ Trim │ 8. 🪚 Split │ 9. 🛠️ Edit │
2022-04-21 15:21:51 +00:00
├────────────────────────┼──────────────────────────┼──────────────────────────┤
2022-04-25 11:09:23 +00:00
│ 10. ❌ Remove │ 11. ❎ Exit │ │
2022-04-21 15:21:51 +00:00
╰────────────────────────┴──────────────────────────┴──────────────────────────╯"
2022-04-21 14:06:35 +00:00
read -p "Enter Selection:" P
case $P in
2022-04-25 11:09:23 +00:00
'' ) killall mplayer > /dev/null 2>& 1 ; BROWSE_NEXT = true; GO = true
2022-04-21 14:06:35 +00:00
; ;
2022-04-25 11:09:23 +00:00
1) killall mplayer > /dev/null 2>& 1 ; BROWSE_NEXT = true; GO = true
2022-04-21 14:06:35 +00:00
; ;
2022-04-23 12:19:46 +00:00
2) if [ [ -e " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV ] ] ; then killall mplayer > /dev/null 2>& 1 ; mplayer -really-quiet " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV & else echo "There is no file " " $DIRECTORY " "Sapo_" " $NAME " /" $ERROR_WAV " "." ; fi
2022-04-21 14:06:35 +00:00
; ;
2022-04-25 11:09:23 +00:00
3) killall mplayer > /dev/null 2>& 1 ; echo "Old line: " $TEXT_TO_CORRECT ; read -p "Enter the corrected line to render: " s; if [ [ -n $s ] ] ; then echo "Please wait..." ; tts --text " $s " --out_path " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV > /dev/null 2>& 1 ; mplayer -really-quiet " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV & fi
2022-04-21 14:06:35 +00:00
; ;
2022-04-25 11:09:23 +00:00
4) killall mplayer > /dev/null 2>& 1 ; read -p "Go To Line: " ERROR_LINE; if [ [ -n $ERROR_LINE ] ] ; then ( ( ERROR_LINE--) ) ; GO = true; fi
2022-04-21 14:06:35 +00:00
; ;
2022-04-25 11:09:23 +00:00
5) killall mplayer > /dev/null 2>& 1 ; GO = true; ERROR_LINE = $(( $ERROR_LINE - 2 ))
2022-04-21 14:06:35 +00:00
; ;
2022-04-25 11:09:23 +00:00
6) killall mplayer > /dev/null 2>& 1 ; GO = true
2022-04-21 14:06:35 +00:00
; ;
2022-04-25 11:09:23 +00:00
7) killall mplayer > /dev/null 2>& 1 ; 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-04-21 14:06:35 +00:00
; ;
2022-04-25 11:09:23 +00:00
8) killall mplayer > /dev/null 2>& 1 ; echo "Old line: " $TEXT_TO_CORRECT ; read -p "Enter the first half of line to render: " s1 ; read -p "Enter the second half of line to render: " s2 ; if [ [ -n $s1 ] ] && [ [ -n $s2 ] ] ; then echo "Please wait..." ; tts --text " $s1 " --out_path " $DIRECTORY " "Sapo_" " $NAME " /1temp.wav > /dev/null 2>& 1 ; tts --text " $s2 " --out_path " $DIRECTORY " "Sapo_" " $NAME " /2temp.wav > /dev/null 2>& 1 ; 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; mplayer -really-quiet " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV & fi
2022-04-21 14:06:35 +00:00
; ;
2022-04-25 11:09:23 +00:00
9) killall mplayer > /dev/null 2>& 1 ; echo "Opening audio editor..." ; $AUDIO_EDITOR " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV > /dev/null 2>& 1
2022-04-21 14:06:35 +00:00
; ;
2022-04-25 11:09:23 +00:00
10) killall mplayer > /dev/null 2>& 1 ; if [ [ -e " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV ] ] ; then rm " $DIRECTORY " "Sapo_" " $NAME " /$ERROR_WAV ; echo " * $DIRECTORY " "Sapo_" " $NAME " /" $ERROR_WAV " " has been deleted." ; sleep 2; else echo "* There is no file " " $DIRECTORY " "Sapo_" " $NAME " /" $ERROR_WAV " " .
Already deleted?" ; sleep 2;fi;GO=true;((ERROR_LINE--))
; ;
11) exit
2022-04-21 14:06:35 +00:00
; ;
esac
done
( ( ERROR_LINE++) )
done
sox " $DIRECTORY " "Sapo_" " $NAME " /*.wav " $DIRECTORY " "Sapo_" " $NAME " /" $NAME " .wav
2022-04-23 12:19:46 +00:00
read -p "Reading of " " $NAME " " is complete!
Press Enter to exit: " db