#!/bin/bash # # ▗▄▖ ▄▄ █ ▗▄▖ █ #▗▛▀▜ ▐▛▀ ▀ ▝▜▌ ▀ #▐▙ ▟██▖▐▙█▙ ▟█▙ ▐███ ██ ▝█ █▘ ▟██▖ ▐▌ ██ # ▜█▙ ▘▄▟▌▐▛ ▜▌▐▛ ▜▌ ▐▌ █ ▐█▌ ▐▛ ▘ ▐▌ █ # ▜▌▗█▀▜▌▐▌ ▐▌▐▌ ▐▌ ██▌ ▐▌ █ ▗█▖ ██▌ ▐▌ ▐▌ █ #▐▄▄▟▘▐▙▄█▌▐█▄█▘▝█▄█▘ ▐▌ ▗▄█▄▖ ▟▀▙ ▝█▄▄▌ ▐▙▄ ▗▄█▄▖ # ▀▀▘ ▀▀▝▘▐▌▀▘ ▝▀▘ ▝▘ ▝▀▀▀▘▝▀ ▀▘ ▝▀▀ ▀▀ ▝▀▀▀▘ # ▐▌ # # a tts bash script by Christos Angelopoulos, April 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` italic="\x1b[3m" 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}${italic}╭──────────────────────────────────────────────────────────────────────────────╮ $BOXTEXT ╰──────────────────────────────────────────────────────────────────────────────╯${normal} ╭────────────────────────┬──────────────────────────┬──────────────────────────╮ │ 1. ⏩ Browse │ 2. ▶️ Play │ 3. 🔃 Render │ ├────────────────────────┼──────────────────────────┼──────────────────────────┤ │ 4. 👉 Go To │ 5. ⬅️ Previous │ 6. ➡️ Next │ ├────────────────────────┼──────────────────────────┼──────────────────────────┤ │ 7. ✂️ Trim │ 8. 🪚 Split │ 9. 🛠️ Edit │ ├────────────────────────┼──────────────────────────┼──────────────────────────┤ │ 10. ❌ Remove │ 11. ❎ Exit │ │ ╰────────────────────────┴──────────────────────────┴──────────────────────────╯" read -p "Enter Selection:" P case $P in '') killall mplayer > /dev/null 2>&1 ;BROWSE_NEXT=true; GO=true ;; 1) killall mplayer > /dev/null 2>&1 ;BROWSE_NEXT=true; GO=true ;; 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 ;; 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 ;; 4)killall mplayer > /dev/null 2>&1 ;read -p "Go To Line: " ERROR_LINE; if [[ -n $ERROR_LINE ]];then ((ERROR_LINE--));GO=true;fi ;; 5)killall mplayer > /dev/null 2>&1 ; GO=true; ERROR_LINE=$(($ERROR_LINE - 2)) ;; 6) killall mplayer > /dev/null 2>&1 ;GO=true ;; 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 ;; 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 ;; 9)killall mplayer > /dev/null 2>&1 ;echo "Opening audio editor...";$AUDIO_EDITOR "$DIRECTORY""Sapo_""$NAME"/$ERROR_WAV > /dev/null 2>&1 ;; 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 ;; 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