mirror of https://gitlab.com/christosangel/sapo
139 lines
9.5 KiB
Bash
Executable File
139 lines
9.5 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# ▗▄▖ ▄▄ █ ▗▄▖ █
|
|
#▗▛▀▜ ▐▛▀ ▀ ▝▜▌ ▀
|
|
#▐▙ ▟██▖▐▙█▙ ▟█▙ ▐███ ██ ▝█ █▘ ▟██▖ ▐▌ ██
|
|
# ▜█▙ ▘▄▟▌▐▛ ▜▌▐▛ ▜▌ ▐▌ █ ▐█▌ ▐▛ ▘ ▐▌ █
|
|
# ▜▌▗█▀▜▌▐▌ ▐▌▐▌ ▐▌ ██▌ ▐▌ █ ▗█▖ ██▌ ▐▌ ▐▌ █
|
|
#▐▄▄▟▘▐▙▄█▌▐█▄█▘▝█▄█▘ ▐▌ ▗▄█▄▖ ▟▀▙ ▝█▄▄▌ ▐▙▄ ▗▄█▄▖
|
|
# ▀▀▘ ▀▀▝▘▐▌▀▘ ▝▀▘ ▝▘ ▝▀▀▀▘▝▀ ▀▘ ▝▀▀ ▀▀ ▝▀▀▀▘
|
|
# ▐▌
|
|
#
|
|
# 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
|
|
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############
|
|
|
|
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"
|
|
;;
|
|
"") LINES_TO_EDIT="ALL"
|
|
;;
|
|
2) 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
|
|
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
|
|
Yellow="\033[1;33m"
|
|
bold=`tput bold`
|
|
normal=`tput sgr0`
|
|
|
|
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
|
|
BOXTEXT=$(echo "$TEXT_TO_CORRECT"|fold -w 78 -s|sed 's/$/ /g'|sed 's/\(^.\{1,78\}\).*/\1/'|sed 's/^/│/g;s/$/│/g')
|
|
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/')
|
|
echo -e "╭──────────────────────────────────────┬───────────────────────────────────────╮
|
|
│$BOXFIRSTLINE│ $BOXDURATION│
|
|
╰──────────────────────────────────────┴───────────────────────────────────────╯
|
|
${Yellow}╭──────────────────────────────────────────────────────────────────────────────╮
|
|
$BOXTEXT
|
|
╰──────────────────────────────────────────────────────────────────────────────╯${normal}
|
|
╭────────────────────────┬──────────────────────────┬──────────────────────────╮
|
|
│1. ⏩ Browse │ 5. ✂️ Trim │ 9. ⬅️ Previous │
|
|
├────────────────────────┼──────────────────────────┼──────────────────────────┤
|
|
│2. ▶️ Play │ 6. 🪚 Split │ 10. ➡️ Next │
|
|
├────────────────────────┼──────────────────────────┼──────────────────────────┤
|
|
│3. ❎ Cancel │ 7. 🛠️ Edit │ 11. 👉 Go To │
|
|
├────────────────────────┼──────────────────────────┼──────────────────────────┤
|
|
│4. 🔃 Render │ 8. ❌ Remove │ │
|
|
╰────────────────────────┴──────────────────────────┴──────────────────────────╯"
|
|
read -p "Enter Selection:" P
|
|
|
|
|
|
case $P in
|
|
10) killall mplayer > /dev/null 2>&1 ;GO=true
|
|
;;
|
|
3) exit
|
|
;;
|
|
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
|
|
;;
|
|
4) killall mplayer > /dev/null 2>&1 ;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
|
|
;;
|
|
5)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
|
|
;;
|
|
6)killall mplayer > /dev/null 2>&1 ;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
|
|
;;
|
|
8)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."; else echo "* There is no file ""$DIRECTORY""Sapo_""$NAME"/"$ERROR_WAV"".
|
|
Already deleted?";fi;GO=true
|
|
;;
|
|
7)killall mplayer > /dev/null 2>&1 ;echo "Opening audio editor...";$AUDIO_EDITOR "$DIRECTORY""Sapo_""$NAME"/$ERROR_WAV > /dev/null 2>&1
|
|
;;
|
|
9)killall mplayer > /dev/null 2>&1 ; GO=true; ERROR_LINE=$(($ERROR_LINE - 2))
|
|
;;
|
|
1) killall mplayer > /dev/null 2>&1 ;BROWSE_NEXT=true; GO=true
|
|
;;
|
|
'') killall mplayer > /dev/null 2>&1 ;BROWSE_NEXT=true; GO=true
|
|
;;
|
|
11)killall mplayer > /dev/null 2>&1 ;read -p "Go To Line: " ERROR_LINE; if [[ -n $ERROR_LINE ]];then ((ERROR_LINE--));GO=true;fi
|
|
esac
|
|
|
|
done
|
|
((ERROR_LINE++))
|
|
done
|
|
sox "$DIRECTORY""Sapo_""$NAME"/*.wav "$DIRECTORY""Sapo_""$NAME"/"$NAME".wav
|
|
read -p "Reading of ""$NAME"" is complete!
|
|
Press Enter to exit: " db
|