Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function exiting()
- {
- espeak -v whisper "$1"
- exit "$2"
- }
- function text_processing_and_storing()
- {
- xclip -o -selection primary | sed -re "$primary_replacement" | tr '\n' ' ' | sed -re "$secondary_replacement" >> "$current_text_fragment_file"
- echo >> "$current_text_fragment_file"
- last_words="…"$(tail -1 "$current_text_fragment_file" | grep -Eo ".{,16}$")
- }
- function total_duration_evaluation()
- {
- number_of_cyrillic_syllables=$(grep -ro "[аеёиоуыэюя]" "$text_directory"/*.txt | wc -l)
- number_of_latin_syllables=$(grep -ro "[aeiouy]" "$text_directory"/*.txt | wc -l)
- number_of_cyrillic_seconds=$(echo "scale=0; $number_of_cyrillic_syllables / 8.3" | bc -l)
- number_of_latin_seconds=$(echo "scale=0; $number_of_latin_syllables / 5" | bc -l)
- number_of_seconds=$(echo "$number_of_cyrillic_seconds + $number_of_latin_seconds" | bc -l)
- number_of_minutes=$(printf "%02d" $((number_of_seconds / 60)))
- number_of_remaining_seconds=$(printf "%02d" $((number_of_seconds % 60)))
- total_duration="$number_of_minutes:$number_of_remaining_seconds"
- }
- initial_dialog_display_flag="True"
- texts_processing_interruption_flag="False"
- last_words="… …"
- # sed replacement patterns. There's a COMBINING ACUTE ACCENT in the
- # second expression.
- primary_replacement='s/\[[^]]*\]//g; s/[́)(}{"|«»]//g; s/#/ решетка /g; s/\*/ астериск /g; s/\+/ плюс /g; s/\// слэш /g; s/</ меньше /g; s/=/ равно /g; s/>/ больше /g; s/@/ собачка /g; s/\\/ бэкслэш /g; s/\^/ циркумфлекс /g; s/_/ подчеркивание /g; s/`/ бэктик /g; s/~/ тильда /g; s/#/ решетка /g; s/\$/ доллар /g; s/&/ амперсанд /g; s/([05-9])[ ]*%/\1 процентов /g; s/1[ ]*%/1 процент /g; s/([2-4])[ ]*%/\1 процента /g; s/%//g; s/([05-9])[ ]*°/\1 градусов /g; s/1[ ]*°/1 градус /g; s/([2-4])[ ]*°/\1 градуса /g; s/°//g; s/-$//g'
- secondary_replacement='s/[[:space:]]+/ /g; s/([A-Za-z][^A-Za-zА-Яа-я]*)([А-Яа-я])/\1\n\2/g; s/([А-Яа-я][^A-Za-zА-Яа-я]*)([A-Za-z])/\1\n\2/g'
- base_directory="/tmp/WTA_$(date +%y-%m-%d_%H-%M-%S)"
- text_directory="$base_directory/text"
- audio_directory="$base_directory/audio"
- mkdir "$base_directory" "$text_directory" "$audio_directory"
- cd "$base_directory" || exiting "Couldn't enter the base directory" 1
- # GTK bookmarks: deletion and creation
- sed -i '/^.*Audible$/d' ~/.config/gtk-3.0/bookmarks
- echo "file://$base_directory Audible" >> ~/.config/gtk-3.0/bookmarks
- while [ "$texts_processing_interruption_flag" == "False" ]; do
- while true; do
- if [ "$initial_dialog_display_flag" == "True" ]; then
- current_text_fragment_file="$text_directory"/$(date +%s%N).txt
- touch "$current_text_fragment_file"
- espeak -v whisper "Primary!" &
- total_duration_evaluation
- yad --title="Written to audible" \
- --text="Total audio duration: $total_duration\nLast stored words: $last_words\nSelect text and / or choose an action: " \
- --button="Append:2" \
- --button="Abort:1" \
- --borders=12 \
- --on-top \
- --geometry=-1-1
- if [ $? -eq 1 ] || [ $? -eq 252 ]; then
- exiting "Aborted!" 1
- else
- text_processing_and_storing
- initial_dialog_display_flag="False"
- fi
- else
- total_duration_evaluation
- yad --title="Written to audible" \
- --text="Total audio duration: $total_duration\nLast stored words: $last_words\nSelect text and / or choose an action: " \
- --button="Append:2" \
- --button="Next article:3" \
- --button="Convert:4" \
- --button="Abort:1" \
- --borders=12 \
- --on-top \
- --geometry=-1-1
- case "$?" in
- 2)
- text_processing_and_storing
- ;;
- 3)
- initial_dialog_display_flag="True"
- break
- ;;
- 4)
- texts_processing_interruption_flag="True"
- break
- ;;
- 1|252)
- exiting "Aborted!" 1
- ;;
- *)
- true
- ;;
- esac
- fi
- done
- if [ "$texts_processing_interruption_flag" == "True" ]; then
- break
- fi
- done
- for file in $text_directory/*.txt; do
- sox -r 44100 -c 1 -n "$audio_directory/$(date +%s%N)".wav synth 3 sine 220 vol -12dB
- while read -r line; do
- audio_chunk_file_path="$audio_directory/$(date +%s%N).wav"
- if [[ "$line" =~ ^.*[А-Яа-я].*$ ]]; then
- echo "$line" | RHVoice-client -s Anna -r 0.5 -v 1 | sox - --norm=-1 -r 44100 -c 1 "$audio_chunk_file_path"
- else
- espeak -s 160 -v english-us "$line" -w /dev/stdout | sox - --norm=-1 -r 44100 -c 1 "$audio_chunk_file_path"
- fi
- done < "$file"
- audio_files_number=$(ls "$audio_directory" | wc -l)
- if [ "$audio_files_number" -ge 1024 ]; then
- ulimit -n $((audio_files_number))
- fi
- sox "$audio_directory/*.wav" ~/Data/shared/"$(date +%d_%H_%M_%S).ogg"
- rm -f "$audio_directory"/*.wav
- done
- exiting "Done!" 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement