diff --git a/Script/a5_pdf.bash b/Script/a5_pdf.bash new file mode 100755 index 0000000..2d2dcdd --- /dev/null +++ b/Script/a5_pdf.bash @@ -0,0 +1,4 @@ +#!/bin/bash + +pdfjam "$1" --scale 0.71 --offset '0 50mm' -o "a5_$1" + diff --git a/Script/a6_pdf.bash b/Script/a6_pdf.bash new file mode 100755 index 0000000..013adee --- /dev/null +++ b/Script/a6_pdf.bash @@ -0,0 +1,4 @@ +#!/bin/bash + +pdfjam "$1" --scale 0.5 --offset '0 75mm' -o "a6_$1" + diff --git a/Script/all_pdf_to_one_file.bash b/Script/all_pdf_to_one_file.bash new file mode 100755 index 0000000..089d5f2 --- /dev/null +++ b/Script/all_pdf_to_one_file.bash @@ -0,0 +1,4 @@ +#!/bin/bash + +convert -density 300 '*.pdf' -density 300 all.pdf + diff --git a/Script/festival_txt2mp3 b/Script/festival_txt2mp3 new file mode 100755 index 0000000..f859e94 --- /dev/null +++ b/Script/festival_txt2mp3 @@ -0,0 +1,8 @@ +#!/bin/sh +in_file=$1 +out_wav_file_name="$1.wav" +out_mp3_file_name="$1.mp3" +cat "$1" | sed 's/[^a-zA-ZА-Яа-я0-9., ]//g' | text2wave -o "$out_wav_file_name" +lame "$out_wav_file_name" "$out_mp3_file_name" +rm "$out_wav_file_name" + diff --git a/Script/pagenum_pdf.bash b/Script/pagenum_pdf.bash new file mode 100755 index 0000000..9d24095 --- /dev/null +++ b/Script/pagenum_pdf.bash @@ -0,0 +1,4 @@ +#!/bin/bash + +# +pdfjam --preamble '\usepackage{fancyhdr} \pagestyle{fancy} \topmargin -65pt \oddsidemargin 150pt \rfoot{} \cfoot{} \rhead{} \chead{\Large\thepage} \renewcommand {\headrulewidth}{0pt} \renewcommand {\footrulewidth}{0pt} ' --pagecommand '\thispagestyle{fancy}' -o "pagenum_$1" "$1" diff --git a/Script/test_speakers b/Script/test_speakers new file mode 100755 index 0000000..7b47e8e --- /dev/null +++ b/Script/test_speakers @@ -0,0 +1,20 @@ +#!/bin/sh +# Общественное достояние, 2024, Алексей Безбородов (Alexei Bezborodov) + +# Тест всех голосов + +in_file=$1 + +declare -a speaker_arr=("oksana" "jane" "omazh" "zahar" "ermil" "silaerkan" "erkanyavas" "alyss" "nick") +declare -a emotion_arr=("neutral" "good" "evil") + +for s in "${speaker_arr[@]}" +do + for e in "${emotion_arr[@]}" + do + echo "speaker ${s} emotion ${e}" + echo "~/txt2mp3_by_yatts -i \"${in_file}\" -o \"${in_file}_${s}_${e}.mp3\" -e \"${e}\" -s \"${s}\"" + ~/txt2mp3_by_yatts -i "${in_file}" -o "${in_file}_${s}_${e}.mp3" -e "${e}" -s "${s}" + done +done + diff --git a/install.sh b/install.sh index fb82861..3c78a45 100644 --- a/install.sh +++ b/install.sh @@ -39,7 +39,7 @@ sudo apt-get install \ texlive texstudio \ systemd-settings-disable-kill-user-processes \ retext \ - gedit gedit-plugins gedit-plugins-latex \ + gedit gedit-plugins gedit-plugin-devhelp gedit-plugins-latex \ cinnamon-full idesk icewm pcmanfm volumeicon mc \ nemo nemo-emblems nemo-fileroller \ nemo-compare nemo-share-common nemo-arronax nemo-preview nemo-python-devel \ diff --git a/video_tools/img_and_wav2video b/video_tools/img_and_wav2video new file mode 100755 index 0000000..a1d42c5 --- /dev/null +++ b/video_tools/img_and_wav2video @@ -0,0 +1,129 @@ +#!/bin/bash +# Общественное достояние, 2024, Алексей Безбородов (Alexei Bezborodov) + +# Озвучивание русского текста из файла pdf и сохранение в видео + +version=1.0 + +# Формат: +# "Однобуквенная команда|Расширенная команда|Справка|Параметр|Значение по умолчанию|Команда на исполнение" +# Параметр: Пусто - нет параметров, : - есть параметр, :: - параметр не обязателен + +common_params=( + "h|help|Посмотреть помощь.|||ShowHelp; exit;" + "v|version|Посмотреть версию программы.|||echo \$version; exit;" + "V|verbose|Подробный вывод.|||verbose=true" + ) + +sound_params=( + "a|audio|Входной файл с аудиодорожкой.|:||" + "b|audio_options||:|'-c:a aac -b:a 128k'|" + ) + +video_params=( + "i|image|Входной файл с изображением.|:||" + "o|output|Выходной видео файл.|:|''|" + "W|video_width|Размер видео в пикселях по ширине. По умолчанию '!DEFAULT!'.|:|1920|" + "H|video_height|Размер видео в пикселях по высоте. По умолчанию '!DEFAULT!'.|:|1080|" + "p|ffmpeg_pre_options|Опции ffmpeg в самом начале. По умолчанию '!DEFAULT!'.|:|'-loop 1 -r 1'|" + "P|ffmpeg_options|Опции ffmpeg. По умолчанию '!DEFAULT!'.|:|'-c:v libx264 -tune stillimage -preset ultrafast -crf 20 -shortest -pix_fmt yuv420p'|" + ) + +all_params=("${common_params[@]}" "${sound_params[@]}" "${video_params[@]}") + +# Загружаем библиотеку +function GetExec { + local exec_file_name="$1" + + exec="./$exec_file_name" + [ ! -f "$exec" ] && exec="~/$exec_file_name" + + echo "$exec" +} + +eval "source $(GetExec "parse_arg_lib")" + +function ShowHelp() { +cat << EOF +Использование: pdf2video -i [-o ] [-hV] +Озвучивание русского текста из файла pdf и сохранение в видео + +Общие параметры +$(ProcessParams common_params Params2Help) + +Параметры звука +$(ProcessParams sound_params Params2Help) + +Параметры видео +$(ProcessParams video_params Params2Help) + +Примеры: + +# Расширенный вывод +img_and_wav2video -i image.jpg -a audio.wav -o out.mp4 -V + +EOF +} + +# ------------------------------------------- + +# Главный цикл обработки входных параметров +eval "$main_loop" + +image_file="$image" +audio_file="$audio" +out_file="$output" + +unuse_param="$*" +if [ "${image_file}" = "" ] || [ "${audio_file}" = "" ] || [ "${unuse_param}" != "" ]; then + [ "${unuse_param}" != "" ] && echo "Параметры не расшифрованы \"$unuse_param\"" + ShowHelp + exit +fi + +[ "$out_file" = "" ] && { out_file="${image_file}.mp4"; +[ $verbose ] && echo "Выходное имя файла \"$out_file\""; } + +#---------------------------------------------------- + +function PlayTime { + local audio_file=$1 + + out=$(soxi -D "${audio_file}") + int=$(echo "$out/1" | bc) + echo "$int" +} + +function MakeVideo { + local image_file=$1 + local audio_file=$2 + local mp4_file=$3 + + local resized_image_file=$(mktemp -t "MakeVideo_resized_page_image_XXXXXXXXXXX.png" +) + + local cmd="ffmpeg -y -i \"${image_file}\" -filter_complex \"[0]scale=${video_width}:${video_height}:force_original_aspect_ratio=decrease,pad=${video_width}:${video_height}:(ow-iw)/2:(oh-ih)/2[scale];[scale]split=2[bg][fg];[bg]drawbox=c=white@1:replace=1:t=fill[bg];[bg][fg]overlay=format=auto\" \"${resized_image_file}\"" + [ $verbose ] && echo "cmd $cmd" + eval "$cmd" + [ $verbose ] && echo "ffmpeg $?" + + local play_time=$(PlayTime "${audio_file}") + [ $verbose ] && echo "play_time ${play_time}" + play_time_plus1=$(( $play_time + 1 )) + + water_mark='' + float_image='' +# video_filter="-filter_complex \"${water_mark}\" -map \"1:a\"" + video_filter="-map 0 -map \"1:a\"" + + cmd="ffmpeg -y ${ffmpeg_pre_options} -i \"${resized_image_file}\" ${float_image} -i \"${audio_file}\" ${video_filter} ${ffmpeg_options} ${audio_options} -t \"${play_time}\" \"${mp4_file}\"" + [ $verbose ] && echo "cmd $cmd" + eval "$cmd" + [ $verbose ] && echo "ffmpeg $?" + + rm "${resized_image_file}" +} + +MakeVideo "${image_file}" "${audio_file}" "${out_file}" + + diff --git a/video_tools/parse_arg_lib b/video_tools/parse_arg_lib new file mode 100755 index 0000000..05f3c12 --- /dev/null +++ b/video_tools/parse_arg_lib @@ -0,0 +1,110 @@ +#!/bin/bash +# Общественное достояние, 2024, Алексей Безбородов (Alexei Bezborodov) + +# Обработка входных параметров + +# Формат: +# "Однобуквенная команда|Расширенная команда|Справка|Параметр|Значение по умолчанию|Команда на исполнение" +# Параметр: Пусто - нет параметров, : - есть параметр, :: - параметр не обязателен + +# Пример +#common_params=( +# "i|input|Входной текстовый файл.|:|'1.txt'|" +# ) + +function ProcessParams { + local iparams=$1[@] + local work_func=$2 + local params=("${!iparams}") + local custom_arg1="$3" + local custom_arg2="$4" + + SAVE_IFS=$IFS + IFS="" + + for (( i=0; i< ${#params[*]}; i++)) + do + p="${params[i]}" + readarray -d "|" -t cur_params <<< "$p" + small_cmd="${cur_params[0]}" + large_cmd="${cur_params[1]}" + comment="${cur_params[2]}" + use_param="${cur_params[3]}" + default="${cur_params[4]}" + custom_cmd="${cur_params[5]}" + + $work_func "$small_cmd" "$large_cmd" "$comment" "$use_param" "$default" "$custom_cmd" "$custom_arg1" "$custom_arg2" + done + + IFS=$SAVE_IFS +} + +param_var='local small_cmd="$1";local large_cmd="$2";local comment="$3";local use_param="$4";local default="$5";local custom_cmd="$6";local custom_arg1="$7";local custom_arg2="$8";' + +function Params2InitVar { + eval "$param_var" + + if [ "$use_param" != '' ]; then + eval "${large_cmd}=${default}" + fi +} + +function Params2Help { + eval "$param_var" + + echo "-${small_cmd}, -${large_cmd}, --${large_cmd}" + echo " ${comment/"!DEFAULT!"/"${!large_cmd}"}" +} + +function Params2small_list { + eval "$param_var" + + echo -n "${small_cmd}${use_param}" +} + +function Params2large_list { + eval "$param_var" + + echo -n ",${large_cmd}${use_param}" +} + +function Params2Case { + eval "$param_var" + + if [ "$custom_arg1" = "-${small_cmd}" ] || [ "$custom_arg1" = "-${large_cmd}" ] || [ "$custom_arg1" = "--${large_cmd}" ]; then + clear_custom_cmd="${custom_cmd//[$'\t\r\n ']/}" + if [ "${clear_custom_cmd}" != "" ]; then + eval "${custom_cmd}" + else + eval "${large_cmd}=\"$custom_arg2\"" + fi + fi +} + +# Инициализация переменных +ProcessParams all_params Params2InitVar + +# $@ is all command line parameters passed to the script. +# -o is for short options like -v +# -l is for long options with double dash like --version +# the comma separates different long options +# -a is for long options with single dash like -version +# Example +# 'h' is a no-value option. +# 'v:' implies that option -v has value and is a mandatory option. ':' means has a value. +# 't::' implies that option -t has value but is optional. '::' means optional. +small_params_list=$(ProcessParams all_params Params2small_list) +small_params_list="${small_params_list:1}" + +large_params_list=$(ProcessParams all_params Params2large_list) +large_params_list="${large_params_list:1}" + +options=$(getopt --long "$large_params_list" -o "$small_params_list" -a -- "$@") + +# set --: +# If no arguments follow this option, then the positional parameters are unset. Otherwise, the positional parameters +# are set to the arguments, even if some of them begin with a ‘-’. +eval set -- "$options" + +main_loop='while true; do cur_arg="$1"; [ "$cur_arg" = "--" ] && { shift; break; }; ProcessParams all_params Params2Case "$cur_arg" "$2"; shift; done' +