├── t2a.jpg ├── wiki.md ├── env.list ├── m2a ├── a2sk ├── c2c ├── t2i ├── t2c ├── i2i ├── q2t ├── s2s ├── p2t ├── a2s ├── a2t ├── README.md ├── p2c ├── m2t ├── t2t ├── t2tr ├── t2a ├── p2a └── a2a /t2a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabrieleRisso/aiyu/HEAD/t2a.jpg -------------------------------------------------------------------------------- /wiki.md: -------------------------------------------------------------------------------- 1 | WIP 2 | 3 | ### t2a: text to audio 4 | 5 | asks gpt3.5turbo and produce an audio response. 6 | 7 | 4 ways of using it: 8 | 9 | * **t2a** file.txt 10 | * **t2a** "your text here" 11 | * **t2a** and a prompt will appear asking you to input text 12 | * create a .txt file at /dev/shm/file.txt and then run **t2a** 13 | 14 | alt_text 15 | -------------------------------------------------------------------------------- /env.list: -------------------------------------------------------------------------------- 1 | #your OPENAI key 2 | OPENAI_API_KEY="" 3 | 4 | #your editor of choice 5 | EDITOR="nano" 6 | 7 | #your preferred language 8 | #lang=${lang:-$(echo ${LANG:0:2})}; 9 | 10 | #the name of the session used to name generated files 11 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 12 | 13 | #with of your terminal 14 | #COLUMNS="150" 15 | 16 | 17 | #files Generated by Whisper 18 | audiow="/dev/shm/audiow_$session.mp3" 19 | voicew="/dev/shm/voicew_$session.mp3" 20 | textw="/dev/shm/textw_$session.txt" 21 | tradw="/dev/shm/tradw_$session.txt" 22 | subw="/dev/shm/subw_$session.srt" 23 | promptw="/dev/shm/promptw_$session.txt" 24 | 25 | #ai Generated files 26 | promptg="/dev/shm/promptg_$session.txt" 27 | voiceg="/dev/shm/vocieg_$session.mp3" 28 | audiog="/dev/shm/audiog_$session.mp3" 29 | textg="/dev/shm/textg_$session.txt" 30 | subg="/dev/shm/subg_$session.srt" 31 | tradg="/dev/shm/tradg_$session.txt" 32 | 33 | # _MODELS = { 34 | # "tiny": "https://huggingface.co/datasets/jordimas/whisper-ct2-v2/resolve/main/dc6a7765cdc8ae7822b1c3068a2f966eddc2549eda7e67406cae915a8c19430c.tiny/", 35 | # "tiny.en": "https://huggingface.co/datasets/jordimas/whisper-ct2-v2/resolve/main/c4d1be0a2003ce00bb721abd23e7a34925a6f0c0d21d5c416f11c763ee7f7b15.tiny-en/", 36 | # "base": "https://huggingface.co/datasets/jordimas/whisper-ct2-v2/resolve/main/d7c4df31737340263ce37933bda1e77a38367dbb09cda7433ce1ee0c58ce1a60.base/", 37 | # "base.en": "https://huggingface.co/datasets/jordimas/whisper-ct2-v2/resolve/main/2ca96777261aeadd48e30bc5f26fd3ee462f4921dbc1f38dfd826a67c761c9b2.base-en/", 38 | # "small": "https://huggingface.co/datasets/jordimas/whisper-ct2-v2/resolve/main/936cd99363be80fa388c0c5006e846d8cd42834c6cf8156a7c300723a3bf929f.small/", 39 | # "small.en": "https://huggingface.co/datasets/jordimas/whisper-ct2-v2/resolve/main/e2c14bb0f6a8a69afe12fbe1d82fa0c41494d4bde9615bdf399da5665f43cbc4.small-en/", 40 | # "medium": "https://huggingface.co/datasets/jordimas/whisper-ct2-v2/resolve/main/d8b91e278db3041c3b41bf879716281edf5cfa7b0025823cc174b5429877d2bc.medium/", 41 | # "medium.en": "https://huggingface.co/datasets/jordimas/whisper-ct2-v2/resolve/main/22d42d3e69ce9149bfd52c07d357e4cb72b992fb602805d6bb39f331400d6742.mediu-en/", 42 | # "large-v1": "https://huggingface.co/datasets/jordimas/whisper-ct2-v2/resolve/main/ea44e7a9609bd21a604b28880b85fc7dc2c373876c627a7553ce5440a8c406c1.large/", 43 | # "large-v2": "https://huggingface.co/datasets/jordimas/whisper-ct2-v2/resolve/main/ff9f410b63b3d996274c895f6209e9b9ab01d497815b21c2d35ae336ab7d7f20.large-v2/", 44 | # } 45 | 46 | 47 | -------------------------------------------------------------------------------- /m2a: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | lang=${lang:-$(echo ${LANG:0:2})}; 6 | 7 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 8 | 9 | audiow="/dev/shm/audiow_$session.mp3" 10 | voicew="/dev/shm/voicew_$session.mp3" 11 | 12 | voiceg="/dev/shm/vocieg_$session.mp3" 13 | audiog="/dev/shm/audiog_$session.mp3" 14 | textg="/dev/shm/textg_$session.txt" 15 | 16 | input="" 17 | output="" 18 | 19 | if ! type m2a 2>/dev/null 1>&2; 20 | then 21 | m2a () 22 | { 23 | if ! python3 -c "import pvrecorder" 2>/dev/null 1>&2; 24 | then 25 | echo "PV_Recorder is not installed on your system. Install it: pip3 install pvrecorder and re-try" >&2; 26 | echo "m2a-pvrecorder is disabled" >&2; 27 | elif ! command -v gum --version 2>/dev/null 1>&2; 28 | then 29 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 30 | else 31 | if ! type m2a-pvrecorder 2>/dev/null 1>&2; 32 | then 33 | m2a-pvrecorder () 34 | { 35 | 36 | set -uo pipefail; 37 | 38 | echo '{{ Bold "[!] record started" }}' | gum format -t template >&2; 39 | 40 | local start=$SECONDS; 41 | 42 | local output="$1"; 43 | local output=${output:-$(echo $audiow)}; 44 | 45 | gum style "using microphone for audio recording." "INPUT: microphone" "OUTPUT: audio saved at $output" "DEVICE: default mic" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 46 | 47 | # subtitle to text: https://github.com/Picovoice/pvrecorder/tree/main/sdk/python 48 | 49 | wget -qO - https://raw.githubusercontent.com/Picovoice/pvrecorder/main/sdk/python/demo.py > /dev/shm/recorder.py 50 | echo '{{ Bold "[+] Recording has started! stop it with CTRL+C" }}' | gum format -t template >&2; 51 | python3 /dev/shm/recorder.py --output_path $output; 52 | 53 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 54 | echo '{{ Bold "[+] recorder OK" }}' | gum format -t template >&2; 55 | 56 | echo '{{ Bold "[?] What now? press ESC to exit." }}' | gum format -t template >&2; 57 | echo ' ' >&2; 58 | 59 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "play recorded audio" "help" "contribute to aiyu"); 60 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="a2t" --height=9); 61 | [[ "$CHOICE" == "play recorded audio" ]] && ffplay -nodisp -autoexit -loglevel fatal $output; 62 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 63 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, thank you for making $(gum style --bold "aiyu") the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 64 | 65 | } 66 | else 67 | echo '{{ Bold "m2a-pvrecorder is set on the system" }}' | gum format -t template >&2; 68 | fi 69 | fi 70 | 71 | m2a-pvrecorder "$1"; 72 | } 73 | else 74 | echo '{{ Bold "m2a is set on the system" }}' | gum format -t template >&2; 75 | fi 76 | -------------------------------------------------------------------------------- /a2sk: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 6 | 7 | voiceg="/dev/shm/voiceg_$session.mp3" 8 | voicew="/dev/shm/voicew_$session.mp3" 9 | 10 | audiog="/dev/shm/audiog_$session.mp3" 11 | 12 | input="" 13 | output="" 14 | 15 | if ! type a2sk 2>/dev/null 1>&2; 16 | then 17 | a2sk () 18 | { 19 | if ! command -v ffplay --version 2>/dev/null 1>&2; 20 | then 21 | echo "ffplay is not installed on your system. Install it and re-try" >&2; 22 | echo "a2sk-ffplay is disabled" >&2; 23 | elif ! command -v gum --version 2>/dev/null 1>&2; 24 | then 25 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 26 | else 27 | if ! type a2sk-ffplay 2>/dev/null 1>&2; 28 | then 29 | a2sk-ffplay () 30 | { 31 | 32 | set -euo pipefail; 33 | 34 | echo '{{ Bold "[!] ffplay started" }}' | gum format -t template >&2; 35 | 36 | local start=$SECONDS; 37 | 38 | local input="$1"; 39 | 40 | #select the lastly created file.mp3 (1 minute old) located in /dev/shm/ OR select a local .mp3 file 41 | local newest_file=""; 42 | local newest_file=$(find /dev/shm/ -cmin -1 -type f -name "*.mp3" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 43 | if [ -n "$newest_file" ]; then 44 | echo '{{ Bold "[>] Selecting most recent audio file --> '$newest_file'" }}' | gum format -t template >&2; 45 | local input=${input:-$(echo $newest_file)}; 46 | else 47 | echo '{{ Bold "[+] Select a mp3 file. Use keyboard arrows < > to traverse directories, up or down arrows to move in the directory." }}' | gum format -t template >&2; 48 | local input=$(gum file $PWD); 49 | fi 50 | 51 | gum style "using ffplay to reproduce audio with speaker." "INPUT: audio saved at $input" "OUTPUT: default audio speaker" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 52 | 53 | ffplay -nodisp -autoexit -loglevel fatal $input; 54 | 55 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 56 | echo '{{ Bold "[+] ffplay OK" }}' | gum format -t template >&2; 57 | 58 | echo '{{ Bold "[?] What now? press ESC to exit." }}' | gum format -t template >&2; 59 | echo ' ' >&2; 60 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "play input audio" "help" "contribute to aiyu"); 61 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="a2t" --height=9); 62 | [[ "$CHOICE" == "play input audio" ]] && ffplay -nodisp -autoexit -loglevel fatal $input; 63 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 64 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, thank you for making $(gum style --bold "aiyu") the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 65 | 66 | return 1; 67 | } 68 | else 69 | echo '{{ Bold "a2sk-ffplay is set on the system" }}' | gum format -t template >&2; 70 | fi 71 | fi 72 | 73 | a2sk-ffplay "$1"; 74 | } 75 | else 76 | echo '{{ Bold "a2sk is set on the system" }}' | gum format -t template >&2; 77 | fi 78 | -------------------------------------------------------------------------------- /c2c: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | lang=${lang:-$(echo ${LANG:0:2})}; 6 | 7 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 8 | 9 | 10 | 11 | 12 | 13 | #promptw="/dev/shm/promptw_$session.txt" 14 | #promptg="/dev/shm/promptg_$session.txt" 15 | 16 | 17 | #textg="/dev/shm/textg_$session.txt" 18 | codeg="/dev/shm/codeg_$session" 19 | 20 | input="" 21 | output="" 22 | tmp="" 23 | 24 | if ! type c2c 2>/dev/null 1>&2; 25 | then 26 | c2c () 27 | { 28 | if ! command -v npm --version 2>/dev/null 1>&2; 29 | then 30 | echo " npm is not installed on your system. Install it: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm#using-a-node-version-manager-to-install-nodejs-and-npm and re-try" >&2; 31 | echo " c2c is disabled" >&2; 32 | elif ! command -v gum --version 2>/dev/null 1>&2; 33 | then 34 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 35 | else 36 | if ! type c2c-codetrans 2>/dev/null 1>&2; 37 | then 38 | 39 | #echo '{{ Bold "[*] language: '$lang' " }}' | gum format -t template >&2; 40 | echo '{{ Bold "[*] session: '$session' " }}' | gum format -t template >&2; 41 | 42 | c2c-codetrans () 43 | { 44 | 45 | echo '{{ Bold "[!] c2c-codetrans started" }}' | gum format -t template >&2; 46 | 47 | if [ -z ${OPENAI_API_KEY+x} ]; then echo '{{ Bold "[!] OPENAI_API_KEY not set! type: export OPENAI_API_KEY=\"your-key-here\" " }}' | gum format -t template >&2; return 1; fi 48 | 49 | local start=$SECONDS; 50 | 51 | echo '{{ Bold "[+] copy-paste your openai api key:'$OPENAI_API_KEY' " }}' | gum format -t template >&2; 52 | 53 | 54 | #-------------------------------------x 55 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Git to install code translator web interface..." --\ 56 | git clone https://github.com/mckaywrigley/ai-code-translator.git; cd ai-code-translator/ && npm i; 57 | 58 | echo '{{ Bold "[t] open your browser at the below address: startup done in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 59 | 60 | #run web interface 61 | echo '{{ Bold "[+] copy-paste your traduction to : '$codeg' " }}' | gum format -t template >&2; 62 | 63 | echo '{{ Bold "[?] press CTRL-C to exit." }}' | gum format -t template >&2; 64 | echo ' ' >&2; 65 | 66 | npm run dev & 67 | 68 | open http://localhost:3000; 69 | 70 | #porobably we can inject code and parameters can be auto detected like t2tr --> c2tr. only needed params is c2tr $langto, like in t2tr fr ( translate text in french) 71 | #-------------------------------------x 72 | 73 | while read -r -n1 key 74 | do 75 | # if input == ESC key 76 | if [[ $key == $'\e' ]]; 77 | then 78 | break; 79 | fi 80 | 81 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "edit output text in glow" "edit input text in glow" "help" "contribute to aiyu"); 82 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="c2c"code-to-codeeight=9); 83 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 84 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, thank you for making $(gum style --bold "aiyu") is the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 85 | 86 | done; 87 | 88 | } 89 | else 90 | echo '{{ Bold " c2c-codetrans is set on the system." }}' | gum format -t template >&2; 91 | fi 92 | fi 93 | 94 | c2c-codetrans; 95 | } 96 | else 97 | echo '{{ Bold "c2c installed on the system" }}' | gum format -t template >&2; 98 | fi 99 | 100 | -------------------------------------------------------------------------------- /t2i: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | #fboulnois_stable-diffusion-docker_ Run the official Stable Diffusion releases in a Docker container with txt2img, img2img, depth2img, pix2pix, upscale4x, and inpaint. 6 | 7 | filter=filter.rnn && wget -qO $filter https://raw.githubusercontent.com/GregorR/rnnoise-models/master/somnolent-hogwash-2018-09-01/sh.rnnn 8 | 9 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 10 | 11 | 12 | 13 | 14 | audiow="/dev/shm/audiow_$session.mp3" 15 | voicew="/dev/shm/voicew_$session.mp3" 16 | textw="/dev/shm/textw_$session.txt" 17 | tradw="/dev/shm/tradw_$session.txt" 18 | subw="/dev/shm/subw_$session.srt" 19 | imgw="/dev/shm/imgw_$session.png" 20 | 21 | 22 | voiceg="/dev/shm/vocieg_$session.mp3" 23 | audiog="/dev/shm/audiog_$session.mp3" 24 | textg="/dev/shm/textg_$session.txt" 25 | askg="/dev/shm/askg_$session.txt" 26 | subg="/dev/shm/subg_$session.srt" 27 | imgg="/dev/shm/imgg_$session.png" 28 | 29 | 30 | input="" 31 | output="" 32 | tmp="" 33 | 34 | #not tested 35 | 36 | if ! type t2i 2>/dev/null 1>&2; 37 | then 38 | t2i () 39 | { 40 | 41 | if ! command -v docker --version 2>/dev/null 1>&2; 42 | then 43 | echo " docker is not installed on your system. Install it: https://docs.docker.com/engine/install and re-try" >&2; 44 | echo "sdimg is disabled" >&2; 45 | elif ! command -v gum --version 2>/dev/null 1>&2; 46 | then 47 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 48 | echo "sdimg is disabled" >&2; 49 | else 50 | if ! type sdimg 2>/dev/null 1>&2; 51 | then 52 | 53 | echo '{{ Bold "[*] session: '$session' " }}' | gum format -t template >&2; 54 | 55 | sdimg () 56 | { 57 | 58 | 59 | echo '{{ Bold "[!] sgpt started" }}' | gum format -t template >&2; 60 | 61 | 62 | input="$1"; 63 | local newest_file=$(stat -c '%Y %n' /dev/shm/*.png | sort -nr | head -n1 | cut -d' ' -f2); 64 | 65 | 66 | echo '{{ Bold "[!] most recent file --> '$newest_file'" }}' | gum format -t template >&2; 67 | 68 | [ -f $newest_file ] && local input=${input:-$(echo $newest_file)} || local input=${input:-$(echo $(gum input --char-limit=4000 --placeholder="Type something here, just ask me!" --width="$(($COLUMNS-5))" --header="I'm an AI use me wisely!" --header.italic --header.border="rounded" --header.foreground="50" ))}; 69 | 70 | #takes function input or if empty asks for inputs 71 | 72 | if [ -z "$input" ]; 73 | then 74 | echo "No input" >&2; 75 | return 1; 76 | fi 77 | 78 | echo $input > $askg >&2; 79 | 80 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Docker to interact with sgpt..." --\ 81 | ./build.sh run "$input"; #https://github.com/fboulnois/stable-diffusion-docker#huggingface-token 82 | 83 | local output=$(stat -c '%Y %n' $PWD/output/*.png | sort -nr | head -n1 | cut -d' ' -f2); 84 | 85 | 86 | if [ -z "$output" ]; 87 | then 88 | echo '{{ Bold "someting went wrong, check https://github.com/fboulnois/stable-diffusion-docker and try again...' | gum format -t template >&2; 89 | return 1; 90 | fi 91 | 92 | gum style "INPUT: saved $askg" "$input" "OUTPUT: image saved at "$output" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 93 | 94 | 95 | echo '{{ Bold "[+] sdimg started" }}' | gum format -t template >&2; 96 | } 97 | else 98 | echo '{{ Color "50" "0" " t2i-sdimg is set on the system." }}' | gum format -t template >&2; 99 | fi 100 | fi 101 | 102 | 103 | t2i-sdimg "$1"; 104 | } 105 | else 106 | echo '{{ Bold "t2i is set on the system" }}' | gum format -t template >&2; 107 | fi 108 | -------------------------------------------------------------------------------- /t2c: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | 6 | lang=${lang:-$(echo ${LANG:0:2})}; 7 | 8 | filter=filter.rnn && wget -qO $filter https://raw.githubusercontent.com/GregorR/rnnoise-models/master/somnolent-hogwash-2018-09-01/sh.rnnn 9 | 10 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 11 | 12 | audiow="/dev/shm/audiow_$session.mp3" 13 | voicew="/dev/shm/voicew_$session.mp3" 14 | textw="/dev/shm/textw_$session.txt" 15 | tradw="/dev/shm/tradw_$session.txt" 16 | subw="/dev/shm/subw_$session.srt" 17 | codew="/dev/shm/codew_$session.txt" 18 | 19 | 20 | voiceg="/dev/shm/vocieg_$session.mp3" 21 | audiog="/dev/shm/audiog_$session.mp3" 22 | textg="/dev/shm/textg_$session.txt" 23 | askg="/dev/shm/askg_$session.txt" 24 | tradg="/dev/shm/tradg_$session.txt" 25 | codeg="/dev/shm/codeg_$session.txt" 26 | 27 | subg="/dev/shm/subg_$session.srt" 28 | input="" 29 | output="" 30 | tmp="" 31 | 32 | if ! type t2c 2>/dev/null 1>&2; 33 | then 34 | t2c () 35 | { 36 | 37 | 38 | if ! command -v docker --version 2>/dev/null 1>&2; 39 | then 40 | echo " Gum docker is not installed on your system. Install it: https://docs.docker.com/engine/install and re-try" >&2; 41 | echo "o-sgpc is disabled" >&2; 42 | elif ! command -v gum --version 2>/dev/null 1>&2; 43 | then 44 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 45 | echo "o-sgpc is disabled" >&2; 46 | else 47 | if ! type o-sgpc 2>/dev/null 1>&2; 48 | then 49 | o-sgpc () 50 | { 51 | 52 | 53 | local input="$1"; 54 | #takes function "textg" parmaeter as input or if empty prompts for input 55 | local input=${input:-$(echo $(gum input --char-limit=4000 --placeholder="Type something here, just askg me!" --width="$(($COLUMNS-5))" --header="I'm an AI, use me wisely!" --header.italic --header.border="rounded" --header.foreground="50" ) )}; 56 | if [ -z "$input" ]; 57 | then 58 | echo "No input" >&2; 59 | return 1; 60 | fi 61 | 62 | echo $input > $askg > /dev/null ; 63 | 64 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Docker to interact with sgpc..." --\ 65 | docker run --rm --env OPENAI_API_KEY -v gpt-cache:/tmp/shell_gpt ghcr.io/ther1d/shell_gpt --no-animation --code "$input" > "$codeg"; 66 | gum confirm --negative="no" --affirmative="yes, let's read " "open pager to read subgtitles?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 140" && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < o-sgpt.log ; 67 | 68 | 69 | local output=$(cat $codeg | tr -d '\n'); 70 | 71 | if [ -z "$output" ]; 72 | then 73 | echo '{{ Bold "Open.ai servers are probably down or unreachable, try again...}}' | gum format -t template >&2; 74 | return 1; 75 | fi 76 | 77 | 78 | gum style "INPUT: saved at $askg" "$input" "OUTPUT: saved at $codeg" "$output" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 79 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read output?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 80 | && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $codeg; 81 | echo '{{ Bold "[+] sgpc OK" }}' | gum format -t template >&2; 82 | 83 | } 84 | 85 | 86 | else 87 | echo '{{ Color "50" "0" " o-sgpc is set on the system." }}' | gum format -t template >&2; 88 | fi 89 | fi 90 | 91 | 92 | o-sgpc "$1"; 93 | } 94 | else 95 | echo '{{ Bold "t2c is set on the system" }}' | gum format -t template >&2; 96 | fi 97 | -------------------------------------------------------------------------------- /i2i: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | #fboulnois_stable-diffusion-docker_ Run the official Stable Diffusion releases in a Docker container with txi2img, img2img, depth2img, pix2pix, upscale4x, and inpaint. 6 | 7 | filter=filter.rnn && wget -qO $filter https://raw.githubusercontent.com/GregorR/rnnoise-models/master/somnolent-hogwash-2018-09-01/sh.rnnn 8 | 9 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 10 | 11 | 12 | 13 | 14 | audiow="/dev/shm/audiow_$session.mp3" 15 | voicew="/dev/shm/voicew_$session.mp3" 16 | textw="/dev/shm/textw_$session.txt" 17 | tradw="/dev/shm/tradw_$session.txt" 18 | subw="/dev/shm/subw_$session.srt" 19 | imgw="/dev/shm/imgw_$session.png" 20 | 21 | 22 | voiceg="/dev/shm/vocieg_$session.mp3" 23 | audiog="/dev/shm/audiog_$session.mp3" 24 | textg="/dev/shm/textg_$session.txt" 25 | askg="/dev/shm/askg_$session.txt" 26 | subg="/dev/shm/subg_$session.srt" 27 | imgg="/dev/shm/imgg_$session.png" 28 | 29 | 30 | input="" 31 | output="" 32 | tmp="" 33 | 34 | #not tested 35 | 36 | if ! type i2i 2>/dev/null 1>&2; 37 | then 38 | i2i () 39 | { 40 | 41 | if ! command -v docker --version 2>/dev/null 1>&2; 42 | then 43 | echo " docker is not installed on your system. Install it: https://docs.docker.com/engine/install and re-try" >&2; 44 | echo "sdimgi is disabled" >&2; 45 | elif ! command -v gum --version 2>/dev/null 1>&2; 46 | then 47 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 48 | echo "sdimgi is disabled" >&2; 49 | else 50 | if ! type sdimgi 2>/dev/null 1>&2; 51 | then 52 | 53 | echo '{{ Bold "[*] session: '$session' " }}' | gum format -t template >&2; 54 | 55 | sdimgi () 56 | { 57 | 58 | 59 | echo '{{ Bold "[!] i2i started" }}' | gum format -t template >&2; 60 | 61 | local newest_filet=$(stat -c '%Y %n' /dev/shm/*.txt | sort -nr | head -n1 | cut -d' ' -f2); 62 | 63 | local inputt="$1"; 64 | [ -f $newest_file ] && local inputt=${inputt:-$(echo $newest_file)} || local inputt=${inputt:-$(echo $(echo $(gum input --char-limit=4000 --placeholder="Type something here, just ask me!" --width="$(($COLUMNS-5))" --header="I'm an AI use me wisely!" --header.italic --header.border="rounded" --header.foreground="50" ))}; 65 | 66 | local inputv="$2"; 67 | local $newest_filev=$(stat -c '%Y %n' $PWD/output/*.png | sort -nr | head -n1 | cut -d' ' -f2); 68 | [ -f $newest_filev ] && local inputv=${inputv:-$(echo $newest_filev)} || local inputv=${inputv:-$(echo $(gum file $PWD))}; 69 | 70 | echo '{{ Bold "[!] most recent possible prompt --> '$newestt_file'" }}' | gum format -t template >&2; 71 | echo '{{ Bold "[!] most recent image --> '$newestv_file'" }}' | gum format -t template >&2; 72 | 73 | if [ -z "$inputv" ] || [ -z "$inputt" ]; #check that text and voice are set 74 | then 75 | echo "bad inputs" >&2; 76 | return 1; 77 | fi 78 | 79 | echo $input > $askg >&2; 80 | 81 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Docker to interact with stable diffusion..." --\ 82 | ./build.sh run --image "$inputv" "$inputt"; #https://github.com/fboulnois/stable-diffusion-docker#huggingface-token 83 | 84 | local output=$(stat -c '%Y %n' $PWD/output/*.png | sort -nr | head -n1 | cut -d' ' -f2); 85 | 86 | 87 | if [ -z "$output" ]; 88 | then 89 | echo '{{ Bold "someting went wrong, check https://github.com/fboulnois/stable-diffusion-docker and try again...' | gum format -t template >&2; 90 | return 1; 91 | fi 92 | 93 | gum style "INPUT: saved $askg" "$input" "OUTPUT: image saved at $output" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 94 | 95 | 96 | echo '{{ Bold "[+] sdimg started" }}' | gum format -t template >&2; 97 | } 98 | else 99 | echo '{{ Color "50" "0" " i2i-sdimgi is set on the system." }}' | gum format -t template >&2; 100 | fi 101 | fi 102 | 103 | 104 | i2i-sdimgi "$1"; 105 | } 106 | else 107 | echo '{{ Bold "i2i is set on the system" }}' | gum format -t template >&2; 108 | fi 109 | -------------------------------------------------------------------------------- /q2t: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | lang=${lang:-$(echo ${LANG:0:2})}; 6 | 7 | filter=filter.rnn && wget -qO $filter https://raw.githubusercontent.com/GregorR/rnnoise-models/master/somnolent-hogwash-2018-09-01/sh.rnnn 8 | 9 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 10 | 11 | 12 | 13 | 14 | audiow="/dev/shm/audiow_$session.mp3" 15 | voicew="/dev/shm/voicew_$session.mp3" 16 | textw="/dev/shm/textw_$session.txt" 17 | tradw="/dev/shm/tradw_$session.txt" 18 | subw="/dev/shm/subw_$session.srt" 19 | 20 | 21 | voiceg="/dev/shm/vocieg_$session.mp3" 22 | audiog="/dev/shm/audiog_$session.mp3" 23 | textg="/dev/shm/textg_$session.txt" 24 | askg="/dev/shm/askg_$session.txt" 25 | subg="/dev/shm/subg_$session.srt" 26 | input="" 27 | output="" 28 | tmp="" 29 | 30 | if ! type q2t 2>/dev/null 1>&2; 31 | then 32 | q2t () 33 | { 34 | 35 | if ! command -v docker --version 2>/dev/null 1>&2; 36 | then 37 | echo " Gum docker is not installed on your system. Install it: https://docs.docker.com/engine/install and re-try" >&2; 38 | echo "q2t-sgpt is disabled" >&2; 39 | elif ! command -v gum --version 2>/dev/null 1>&2; 40 | then 41 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 42 | else 43 | if ! type q2t-sgpt 2>/dev/null 1>&2; 44 | then 45 | 46 | echo '{{ Bold "[*] language: '$lang' " }}' | gum format -t template >&2; 47 | echo '{{ Bold "[*] session: '$session' " }}' | gum format -t template >&2; 48 | 49 | q2t-sgpt () 50 | { 51 | 52 | 53 | echo '{{ Bold "[!] sgpt started" }}' | gum format -t template >&2; 54 | 55 | 56 | 57 | local input="$1"; 58 | #takes function input or if empty askgs for inputs 59 | local input=${input:-$(echo $(gum input --char-limit=4000 --placeholder="Type something here, just askg me!" --width="$(($COLUMNS-5))" --header="I'm an AI use me wisely!" --header.italic --header.border="rounded" --header.foreground="50" ) )}; 60 | 61 | if [ -z "$input" ]; 62 | then 63 | echo "No input" >&2; 64 | return 1; 65 | fi 66 | 67 | echo $input > $askg >&2; 68 | 69 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Docker to interact with sgpt..." --\ 70 | docker run --rm --env OPENAI_API_KEY -v gpt-cache:/tmp/shell_gpt ghcr.io/ther1d/shell_gpt --no-animation --chat "$session" "$input" > "$textg"; 71 | 72 | local output=$(cat $textg | tr -d '\n') >&2; 73 | 74 | if [ -z "$output" ]; 75 | then 76 | echo '{{ Bold "Open.ai servers are probably down or unreachable, try again...' | gum format -t template >&2; 77 | return 1; 78 | fi 79 | 80 | gum style "INPUT: saved at $askg" "$input" "OUTPUT: saved at $textg" "$output" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 81 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read output?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 82 | && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $textg; 83 | 84 | echo '{{ Bold "[+] sgpt OK" }}' | gum format -t template >&2; 85 | 86 | 87 | 88 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "edit output text in glow" "edit input text in glow" "help" "contribute to aiyu"); 89 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="q2t" --height=9); 90 | [[ "$CHOICE" == "edit output text in glow" ]] && cp $textg "${textw::-4}.md" && glow "/dev/shm/"; 91 | [[ "$CHOICE" == "edit input text in glow" ]] && cp $textg "${textg::-4}.md" && glow "/dev/shm/"; 92 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 93 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, thank you for making $(gum style --bold "aiyu") is the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 94 | 95 | 96 | } 97 | else 98 | echo '{{ Color "50" "0" " q2t-sgpt is set on the system." }}' | gum format -t template >&2; 99 | fi 100 | fi 101 | 102 | 103 | 104 | q2t-sgpt "$1"; 105 | } 106 | else 107 | echo '{{ Bold "q2t is set on the system" }}' | gum format -t template >&2; 108 | fi 109 | -------------------------------------------------------------------------------- /s2s: -------------------------------------------------------------------------------- 1 | 2 | # Small but handy functions. For Personal use only. 3 | # Use it at your own risk! 4 | # Author: Gabriele Risso License: Apache 2.0 5 | 6 | #lang=${lang:-$(echo ${LANG:0:2})}; 7 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 8 | 9 | subg="/dev/shm/subg_$session.txt" 10 | #textg="/dev/shm/textg_$session.txt" 11 | tradg="/dev/shm/tradg_$session.txt" 12 | 13 | 14 | if ! type s2s 2>/dev/null 1>&2; 15 | then 16 | s2s () 17 | { 18 | 19 | if ! command -v docker --version 2>/dev/null 1>&2; 20 | then 21 | echo "trad is not installed on your system. https://github.com/soimort/translate-shell " >&2; 22 | echo "s2s-ttrans is disabled" >&2; 23 | elif ! command -v gum --version 2>/dev/null 1>&2; 24 | then 25 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 26 | else 27 | if ! type s2s-ttrans 2>/dev/null 1>&2; 28 | then 29 | s2s-ttrans () 30 | { 31 | 32 | if [ -z ${OPENAI_API_KEY+x} ]; then echo '{{ Bold "[!] OPENAI_API_KEY not set! type: export OPENAI_API_KEY=\"your-key-here\" " }}' | gum format -t template >&2; return 1; fi 33 | 34 | echo '{{ Bold "[!] traduction started" }}' | gum format -t template >&2; 35 | 36 | local start=$SECONDS; 37 | local input="$2"; 38 | 39 | local newest_file=""; 40 | newest_file=$(find /dev/shm/ -type f -cmin -1 -size +0 -regextype sed -regex ".*\(t\|s\)*.\(txt\|srt\)" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 41 | if [ -n "$newest_file" ]; then 42 | echo '{{ Bold "[!] most recent subtitle file --> '$newest_file'" }}' | gum format -t template >&2; 43 | local input=${input:-$(echo $newest_file)}; 44 | else 45 | echo '{{ Bold "[+] Input prompt" }}' | gum format -t template >&2; 46 | local input=${input:-$(echo $(gum input --char-limit=4000 --placeholder="Type something here, just ask me!" --width="$(($COLUMNS-5))" ) )}; 47 | fi 48 | 49 | local output="$tradg"; 50 | 51 | local langto="$1"; 52 | local langto=${langto:-$(echo "en")}; 53 | local langfrom=${langfrom:-$(echo "auto")}; #sould autodetect language 54 | 55 | gum style "input subtitle: $input" "language from: $langfrom" "output: $output" "language to: $langto" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 56 | 57 | local intrad=""; 58 | intrad=$(<"$input"); 59 | echo $intrad > $subg >&2; 60 | 61 | #------------------------------------------------------------# 62 | #using https://github.com/soimort/translate-shell 63 | gum spin --spinner points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using trad for translation generation..." -- sleep 2 64 | docker run --rm -it soimort/translate-shell -shell -brief -w 10 :"$langto" "$intrad" | tail -n +3 > $output; 65 | #------------------------------------------------------------# 66 | 67 | # prints to terminal 68 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 69 | 70 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read translation?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 71 | && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $output; 72 | 73 | echo '{{ Bold "[+] translation OK" }}' | gum format -t template >&2; 74 | echo '{{ Bold "[?] What now? press ESC to exit." }}' | gum format -t template >&2; 75 | echo ' ' >&2; 76 | 77 | 78 | while read -r -n1 key 79 | do 80 | # if input == ESC key 81 | if [[ $key == $'\e' ]]; 82 | then 83 | break; 84 | fi 85 | 86 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "edit output translation in glow" "edit input subtitle in glow" "help" "contribute to aiyu"); 87 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="s2s" --height=18); 88 | [[ "$CHOICE" == "edit output translation in glow" ]] && cp $tradg "${tradg::-4}.md" && glow "/dev/shm/"; 89 | [[ "$CHOICE" == "edit input subtitle in glow" ]] && cp $input "${input::-4}.md" && glow "/dev/shm/"; 90 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 91 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, thank you for making $(gum style --bold "aiyu") is the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 92 | 93 | done; 94 | 95 | } 96 | else 97 | echo "s2s-ttrans is set on the system.To use it: \"s2s-ttrans lang file.txt \" " >&2; 98 | fi 99 | fi 100 | 101 | s2s-ttrans "$1" "$2"; 102 | #s2s-dtrans "$1" "$2"; 103 | } 104 | else 105 | echo '{{ Bold "s2s is set on the system" }}' | gum format -t template >&2; 106 | fi 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /p2t: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | 6 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 7 | 8 | promptg="/dev/shm/promptg_$session.txt" 9 | textg="/dev/shm/textg_$session.txt" 10 | 11 | 12 | input="" 13 | output="" 14 | 15 | 16 | if ! type p2t 2>/dev/null 1>&2; 17 | then 18 | p2t () 19 | { 20 | 21 | if ! command -v docker --version 2>/dev/null 1>&2; 22 | then 23 | echo " Gum docker is not installed on your system. Install it: https://docs.docker.com/engine/install and re-try" >&2; 24 | echo "p2t-sgpt is disabled" >&2; 25 | elif ! command -v gum --version 2>/dev/null 1>&2; 26 | then 27 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 28 | else 29 | if ! type p2t-sgpt 2>/dev/null 1>&2; 30 | then 31 | 32 | echo '{{ Bold "[*] session: '$session' " }}' | gum format -t template >&2; 33 | 34 | p2t-sgpt () 35 | { 36 | 37 | if [ -z ${OPENAI_API_KEY+x} ]; then echo '{{ Bold "[!] OPENAI_API_KEY not set! type: export OPENAI_API_KEY=\"your-key-here\" " }}' | gum format -t template >&2; return 1; fi 38 | 39 | echo '{{ Bold "[!] sgpt started" }}' | gum format -t template >&2; 40 | 41 | local start=$SECONDS; 42 | 43 | local input="$1"; 44 | local output=""; 45 | 46 | #select the lastly created file.txt (1 minute old) located in /dev/shm/ that macthces t or s as a first char fo the file name OR input prompt directly 47 | local newest_file=""; 48 | newest_file=$(find /dev/shm/ -type f -cmin -1 -size +0 -regextype sed -regex ".*\(t\|s\)*.txt" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 49 | if [ -n "$newest_file" ]; then 50 | echo '{{ Bold "[!] most recent text file --> '$newest_file'" }}' | gum format -t template >&2; 51 | local input=${input:-$(echo $newest_file)}; 52 | else 53 | echo '{{ Bold "[+] Input prompt" }}' | gum format -t template >&2; 54 | local input=${input:-$(echo $(gum input --char-limit=4000 --placeholder="Type something here, just ask me!" --width="$(($COLUMNS-5))" ) )}; 55 | fi 56 | 57 | 58 | #-------------------------------------x 59 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Docker to interact with sgpt..." --\ 60 | docker run --rm --env OPENAI_API_KEY -v gpt-cache:/tmp/shell_gpt ghcr.io/ther1d/shell_gpt --no-animation --chat "$session" "$input" > "$textg"; 61 | #-------------------------------------x 62 | 63 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 64 | 65 | echo $input > $promptg >&2; 66 | 67 | output=$(cat $textg | tr -d '\n') >&2; 68 | 69 | if [ -z "$output" ]; 70 | then 71 | echo '{{ Bold "Openai key could be expired or Servers are probably down or unreachable, try again..." ' | gum format -t template >&2; 72 | return 1; 73 | fi 74 | 75 | gum style "INPUT: saved at $promptg" " " "$input" "OUTPUT: saved at $textg" " " "$output" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 76 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read output?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 77 | && gum pager --border-foreground="86" --help.foreground="200" --show-line-numbers < $textg; 78 | 79 | echo '{{ Bold "[+] sgpt OK" }}' | gum format -t template >&2; 80 | 81 | echo '{{ Bold "[?] What now? press ESC to exit." }}' | gum format -t template >&2; 82 | echo ' ' >&2; 83 | 84 | while read -r -n1 key 85 | do 86 | # if input == ESC key 87 | if [[ $key == $'\e' ]]; 88 | then 89 | break; 90 | fi 91 | 92 | CHOICE=$(gum choose --item.foreground 250 "edit output text in glow" "edit input text in glow" "help" "contribute to aiyu"); 93 | [[ "$CHOICE" == "edit output text in glow" ]] && cp $textg "${textg::-4}.md" && glow "/dev/shm/"; 94 | [[ "$CHOICE" == "edit input text in glow" ]] && cp $promptg "${promptg::-4}.md" && glow "/dev/shm/"; 95 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 96 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, thank you. Leave a $(gum style --bold "star") if you like $(gum style --bold "aiyu"). Go to: https://github.com/GabrieleRisso/aiyu"; 97 | 98 | done; 99 | 100 | } 101 | else 102 | echo '{{ Bold "p2t-sgpt is set on the system." }}' | gum format -t template >&2; 103 | fi 104 | fi 105 | 106 | p2t-sgpt "$1"; 107 | } 108 | else 109 | echo '{{ Bold "p2t is set on the system" }}' | gum format -t template >&2; 110 | fi -------------------------------------------------------------------------------- /a2s: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | 6 | lang=${lang:-$(echo ${LANG:0:2})}; 7 | 8 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 9 | 10 | audiow="/dev/shm/audiow_$session.mp3" 11 | voicew="/dev/shm/voicew_$session.mp3" 12 | subw="/dev/shm/subw_$session.srt" 13 | 14 | voiceg="/dev/shm/voiceg_$session.mp3" 15 | audiog="/dev/shm/audiog_$session.mp3" 16 | subg="/dev/shm/subg_$session.srt" 17 | 18 | 19 | input="" 20 | output="" 21 | 22 | 23 | if ! type a2s 2>/dev/null 1>&2; 24 | then 25 | a2s () 26 | { 27 | if ! command -v whisper-ctranslate2 2>/dev/null 1>&2; 28 | then 29 | echo "whisper-ctranslate2 is not installed on your system. Install it: pip install -U whisper-ctranslate2" >&2; 30 | echo "o-whis is disabled" >&2; 31 | elif ! command -v gum --version 2>/dev/null 1>&2; 32 | then 33 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 34 | else 35 | if ! type a2s-whisp 2>/dev/null 1>&2; 36 | then 37 | 38 | echo '{{ Bold "[*] session: '$session' " }}' | gum format -t template >&2; 39 | 40 | a2s-whisp () 41 | { 42 | 43 | #set -euo pipefail; 44 | 45 | echo '{{ Bold "[!] whisper subtitles started" }}' | gum format -t template >&2; 46 | 47 | if [ -z ${OPENAI_API_KEY+x} ]; then echo '{{ Bold "[!] OPENAI_API_KEY not set! type: export OPENAI_API_KEY=\"your-key-here\" " }}' | gum format -t template >&2; return 1; fi 48 | 49 | local start=$SECONDS; 50 | 51 | local formatsub=${formatsub:-$(echo "srt")}; 52 | local model=${model:-$(echo "medium")}; 53 | #if input text exis then set it as input, if not select it 54 | 55 | local input="$1"; 56 | #1 is te counter time. 0 to achive full flow test 57 | #select the lastly created file.mp3 (1 minute old) located in /dev/shm/ OR select a local .mp3 file 58 | local newest_file=""; 59 | local newest_file=$(find /dev/shm/ -cmin -1 -type f -name "*.mp3" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 60 | if [ -n "$newest_file" ]; then 61 | echo '{{ Bold "[!] most recent file --> '$newest_file'" }}' | gum format -t template >&2; 62 | local input=${input:-$(echo $newest_file)}; 63 | else 64 | echo '{{ Bold "[+] Select a mp3 file. Use keyboard arrows < > to traverse directories, up or down arrows to move in the directory." }}' | gum format -t template >&2; 65 | local input=$(gum file $PWD); 66 | fi 67 | 68 | #output definition 69 | local output="$2"; 70 | local output=${output:-$(echo $subw)}; 71 | 72 | gum style "INPUT audio located at: $input" "INput audio language: auto" "OUTPUT subtitles saved at $output" "OUTput language: auto" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 73 | 74 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Whisper for subtitles creation... this can take a short while" --\ 75 | whisper-ctranslate2 $input --output_format $formatsub --task transcribe --compute_type int8 --output_dir /dev/shm/ ; 76 | #choose best model 77 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 78 | 79 | #rename subtitle file to the output name 80 | local tmpsub=$(basename $input); 81 | mv "/dev/shm/${tmpsub%.*}.$formatsub" $output; 82 | 83 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read subtitles?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 84 | && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $output; 85 | 86 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 87 | echo '{{ Bold "[+] subtitles OK" }}' | gum format -t template >&2; 88 | 89 | echo '{{ Bold "[?] What now? press ESC to exit." }}' | gum format -t template >&2; 90 | echo ' ' >&2; 91 | 92 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "edit output subtitles in glow" "play input audio" "help" "contribute to aiyu"); 93 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="a2s" --height=9); 94 | [[ "$CHOICE" == "edit output subtitles in glow" ]] && cp $subw "${subw::-4}.md" && glow "/dev/shm/"; 95 | [[ "$CHOICE" == "play input audio" ]] && ffplay -nodisp -autoexit -loglevel fatal $input; 96 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 97 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, thank you for making $(gum style --bold "aiyu") is the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 98 | 99 | } 100 | else 101 | echo "a2s-whisp is set on the system. To use it: o-a2s \"input.mp3\" \"output.mp3\" " >&2; 102 | fi 103 | fi 104 | 105 | a2s-whisp "$1" "$2"; 106 | 107 | } 108 | else 109 | echo '{{ Bold "a2s is set on the system" }}' | gum format -t template >&2; 110 | fi 111 | -------------------------------------------------------------------------------- /a2t: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | 6 | #lang=${lang:-$(echo ${LANG:0:2})}; 7 | 8 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 9 | 10 | 11 | textw="/dev/shm/textw_$session.txt" 12 | audiow="/dev/shm/audiow_$session.mp3" 13 | 14 | 15 | if ! type a2t 2>/dev/null 1>&2; 16 | then 17 | a2t () 18 | { 19 | if ! command -v whisper-ctranslate2 2>/dev/null 1>&2; 20 | then 21 | echo "whisper-ctranslate2 is not installed on your system. Install it: pip install -U whisper-ctranslate2" >&2; 22 | echo "if it's your first time whisper is going to install a medium sized model (2.85 GB)" 23 | echo "a2t is disabled" >&2; 24 | elif ! command -v gum --version 2>/dev/null 1>&2; 25 | then 26 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 27 | else 28 | if ! type a2t-whisp 2>/dev/null 1>&2; 29 | then 30 | a2t-whisp () 31 | { 32 | 33 | if [ -z ${OPENAI_API_KEY+x} ]; then echo '{{ Bold "[!] OPENAI_API_KEY not set! type: export OPENAI_API_KEY=\"your-key-here\" " }}' | gum format -t template >&2; return 1; fi 34 | 35 | echo '{{ Bold "[*] session: '$session' " }}' | gum format -t template >&2; 36 | echo '{{ Bold "[!] whisper subtitles started" }}' | gum format -t template >&2; 37 | 38 | local start=$SECONDS; 39 | local formatsub=${formatsub:-$(echo "txt")}; 40 | local model=${model:-$(echo "medium")}; 41 | #if input text exis then set it as input, if not select it 42 | local input="$1"; 43 | 44 | #select the lastly created file.mp3 (1 minute old) located in /dev/shm/ OR select a local .mp3 file 45 | local newest_file=""; 46 | newest_file=$(find /dev/shm/ -type f -cmin -1 -size +0 -regextype sed -regex ".*\(a\|v\)*.mp3" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 47 | if [ -n "$newest_file" ]; then 48 | echo '{{ Bold "[!] most recent file --> '$newest_file'" }}' | gum format -t template >&2; 49 | input=${input:-$(echo $newest_file)}; 50 | else 51 | echo '{{ Bold "[+] Select a mp3 file. Use keyboard arrows < > to traverse directories, up or down arrows to move in the directory." }}' | gum format -t template >&2; 52 | input=$(gum file $PWD); 53 | fi 54 | 55 | cp $input $audiow; 56 | 57 | #output definition 58 | local output="$2"; 59 | local output=${output:-$(echo $textw)}; 60 | #local tmpsrt=$(basename $subw); 61 | #local tmptxt=$(basename $output); 62 | 63 | gum style "INPUT audio located at: $input" "INput audio language: auto" "OUTPUT text saved at $output" "OUTput language: auto" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 64 | 65 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Whisper for subtitles creation... this can take a short while" --\ 66 | whisper-ctranslate2 $input --output_format $formatsub --task transcribe --compute_type int8 --output_dir /dev/shm/ ; 67 | #choose best model 68 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 69 | 70 | #rename subtitle file to the output name 71 | local namesrt=""; 72 | namesrt=$(basename $input); 73 | mv "/dev/shm/${namesrt%.*}.$formatsub" "$textw"; 74 | 75 | # subtitle to text: https://github.com/yumstar/srt2text/blob/main/srt2text.py 76 | 77 | #context 78 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read text?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 79 | && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $output; 80 | echo '{{ Bold "[+] subtitles OK" }}' | gum format -t template >&2; 81 | 82 | echo '{{ Bold "[?] What now? press ESC to exit." }}' | gum format -t template >&2; 83 | echo ' ' >&2; 84 | 85 | while read -r -n1 key 86 | do 87 | # if input == ESC key 88 | if [[ $key == $'\e' ]]; 89 | then 90 | break; 91 | fi 92 | 93 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "edit output text in glow" "play input audio" "help" "contribute to aiyu"); 94 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="a2t" --height=9); 95 | [[ "$CHOICE" == "edit output text in glow" ]] && cp $textw "${textw::-4}.md" && glow "/dev/shm/"; 96 | [[ "$CHOICE" == "play input audio" ]] && ffplay -nodisp -autoexit -loglevel fatal $input; 97 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 98 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, thank you for making $(gum style --bold "aiyu") is the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 99 | 100 | done; 101 | 102 | } 103 | 104 | else 105 | echo "a2t is set on the system. To use it: a2t \"input.mp3\" \"output.mp3\" " >&2; 106 | fi 107 | fi 108 | 109 | a2t-whisp "$1" "$2"; 110 | 111 | } 112 | else 113 | echo '{{ Bold "a2t is set on the system" }}' | gum format -t template >&2; 114 | fi 115 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Core shell functions for AI 2 | 3 | ## What is **AIyu**: 4 | In essence, the Aiyu Shell pipelines serve as the interweaving adhesive that binds the various AI components together - a technological superglue of sorts! 5 | 6 | **Aiyu** allows to build pipelines that easlily leverage the most exciting **ai** technologies using any laptop. 7 | 8 | #### example 9 | 10 | ###### input: audio in some language; output: audio in French 11 | ``` 12 | m2a; a2a fr; a2sk 13 | ``` 14 | Listen to your microphone and outputs an audio file (m2a), then use the previously created audio and translate it to French (a2a fr) and lastly plays the audio to your speaker (a2sk). 15 | 16 | 17 | ###### input: audio question in some language; output: audio GPT response in Italian 18 | ``` 19 | m2a; a2p; p2a; a2a it 20 | ``` 21 | Listen to your microphone and outputs an audio file (m2a), then use the created audio and transcribes it to textual prompt (a2p), use the prompt to query GPT3.5-turbo and produce an audio of the answare (p2a) and lastly, use the created audio and translate it to Italian (a2a it). 22 | 23 | 24 | 25 | 26 |
27 | 28 | Glossary of abbreviations 29 | 30 | ## Inputs and Outputs 31 | 32 | ``` 33 | c -> code ex: sourcecode of a python program 34 | p -> prompt ex: "how can I escape the matrix?" 35 | t -> text ex: .txt file of a motivation letter 36 | s -> subtitle ex: .srt file of a movie subtitles 37 | a -> audio ex: .mp3 file of a recorded conference 38 | I/O: {sk -> speaker, m <- microphone} 39 | ``` 40 |
41 | 42 | ### Current state of implemented functions 43 | 44 | | | prompt | text | subtitle | audio | code | 45 | |-----------|-----------|------|----------|-------|---------| 46 | | prompt | `p2p` | `p2t` | `ap2s` * | `p2a` | `p2c` | 47 | | text | t2p | `t2t` | `at2s` * | `t2a` | `p2c` | 48 | | subtitle | - | `s2t` | `s2s` | `s2a` | - | 49 | | audio | `a2p` | `a2t` | `a2s` | `a2a` | a2c | 50 | | code | - | - | - | - | `c2c` | 51 | 52 | 53 | ## Features: 54 | 55 | * **Hackable** 56 | * It support most languages 57 | * **Linux** and **Mac** compatible. Windows is coming soon. 58 | * Beautiful [Charm](https://charm.sh/ "Charm") **TUI interface** written in Go. 59 | * Bash function editor and experimental **Markdown reader**. 60 | * focused on CPU **performance** 61 | * Documented (very soon) 62 |
63 | 64 | Concise pipelines (inputs2output) 65 | 66 | 🔹 Ask gpt and gtts answer to **speaker** (text2speaker) -> t2sk
67 | 🔹 Ask gpt and gtts answer to **audio** (text2audio) -> t2a
68 | 🔹 Ask gpt and produce specifically **code** (code2text) -> c2t
69 | 🔹 Take audio and produce text **transcript** (audio2text) -> a2t
70 | 🔹 Take audio and produce **subtitles** transcript (audio2subtitles) -> a2s
71 | 🔹 Prompt gpt and produce text (prompt2text) -> p2t
72 | 🔹 Take text and translate into text (text2text) -> t2tr
73 | 🔹 Take audio and **enhance quality** into audio (audio2audio) -> a2a
74 | 🔹 Take audio & text transcript and produce subtitles (audio+text2subtitles) -> at2s
75 | 🔹 Take text and stable diffusion produce **image** (text2image) -> t2i
76 | 77 | 78 | 79 |
80 | 81 | ### Screenshots & Tutorial: [Wiki](https://github.com/GabrieleRisso/aiyu/edit/main/wiki.md "Aiyu Wiki") 82 | 83 |

84 | 85 | 86 | ## In the terminal: 87 | 88 | ###### download directory and enter it: 89 | ``` 90 | git clone https://github.com/GabrieleRisso/aiyu.git 91 | cd aiyu/ 92 | ``` 93 | ###### set the key to global scope: 94 | ``` 95 | . env.list 96 | ``` 97 | ###### load a function: 98 | ``` 99 | . t2s 100 | ``` 101 | ###### use it like this: 102 | ``` 103 | t2a "How are you ?" 104 | ``` 105 | 106 | 107 | ##### Dependencies 108 | 109 | They are prompted if missing and a link to install them is provided. Functions mostly leverages Python libs installed via pip and pre-build Docker images. Memory usage statistics will be out soon. 110 | 111 | 112 | ##### Who's project is doing the AI heavy lifting? 113 | 114 | * [shell-gpt](https://github.com/TheR1D/shell_gpt "text-to-text") 115 | * [gtts](https://gtts.readthedocs.io/en/latest/index.html "text-to-speach") 116 | * [aeneas](https://github.com/readbeyond/aeneas "subtitles") 117 | * [translate-shell](https://github.com/soimort/translate-shell "translate") 118 | * [whisper-c2translate](https://github.com/jordimas/whisper-ctranslate2 "audio-to-text") 119 | * [mtts](https://github.com/mozilla/TTS "text-to-vocie") 120 | * [rnnnoise](https://github.com/GregorR/rnnoise-models "noise filter") 121 | * [stable-diffusion](https://github.com/fboulnois/stable-diffusion-docker "image gen") 122 | 123 | 124 | ### Open for collaboartions; let's make **aiyu** awesome toghter 125 | 126 | * per-command tuning 127 | * wiki documentation 128 | * suggestions are desired! 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | ### Citation 137 | If you utilize this reposistory please consider citing it with: 138 | 139 | ``` 140 | @misc{aiyu, 141 | author = {Gabriele Risso}, 142 | title = {aiyu: core shell functions for advanced ai}, 143 | year = {2023}, 144 | publisher = {GitHub}, 145 | journal = {GitHub repository}, 146 | howpublished = {\url{https://github.com/gabrielerisso/aiyu}}, 147 | } 148 | ``` 149 | 150 | ### Copyright 151 | 152 | Copyright © 2023 Gabriele Risso. 153 | 154 | 155 | #### Contact for custom implementation: 156 | ``` 157 | gabriele.risso@protonmail.ch 158 | ``` 159 | -------------------------------------------------------------------------------- /p2c: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | lang=${lang:-$(echo ${LANG:0:2})}; 6 | 7 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 8 | 9 | 10 | 11 | 12 | audiow="/dev/shm/audiow_$session.mp3" 13 | voicew="/dev/shm/voicew_$session.mp3" 14 | textw="/dev/shm/textw_$session.txt" 15 | tradw="/dev/shm/tradw_$session.txt" 16 | subw="/dev/shm/subw_$session.srt" 17 | promptw="/dev/shm/promptw_$session.txt" 18 | 19 | 20 | promptg="/dev/shm/promptg_$session.txt" 21 | 22 | voiceg="/dev/shm/vocieg_$session.mp3" 23 | audiog="/dev/shm/audiog_$session.mp3" 24 | textg="/dev/shm/textg_$session.txt" 25 | askg="/dev/shm/askg_$session.txt" 26 | subg="/dev/shm/subg_$session.srt" 27 | codeg="/dev/shm/codeg_$session.txt" 28 | 29 | 30 | input="" 31 | output="" 32 | tmp="" 33 | 34 | if ! type p2c 2>/dev/null 1>&2; 35 | then 36 | p2c () 37 | { 38 | 39 | if ! command -v docker --version 2>/dev/null 1>&2; 40 | then 41 | echo " Gum docker is not installed on your system. Install it: https://docs.docker.com/engine/install and re-try" >&2; 42 | echo "p2c-sgpt is disabled" >&2; 43 | elif ! command -v gum --version 2>/dev/null 1>&2; 44 | then 45 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 46 | else 47 | if ! type p2c-sgpt 2>/dev/null 1>&2; 48 | then 49 | 50 | echo '{{ Bold "[*] language: '$lang' " }}' | gum format -t template >&2; 51 | echo '{{ Bold "[*] session: '$session' " }}' | gum format -t template >&2; 52 | 53 | p2c-sgpt () 54 | { 55 | 56 | 57 | echo '{{ Bold "[!] sgpt started" }}' | gum format -t template >&2; 58 | 59 | if [ -z ${OPENAI_API_KEY+x} ]; then echo '{{ Bold "[!] OPENAI_API_KEY not set! type: export OPENAI_API_KEY=\"your-key-here\" " }}' | gum format -t template >&2; return 1; fi 60 | 61 | local start=$SECONDS; 62 | 63 | local input="$1"; 64 | 65 | #select the lastly created file.txt (1 minute old) located in /dev/shm/ OR input prompt directly 66 | local newest_file=""; 67 | local newest_file=$(find /dev/shm/ -cmin -1 -type f -name "*.txt" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 68 | if [ -n "$newest_file" ]; then 69 | echo '{{ Bold "[!] most recent text file --> '$newest_file'" }}' | gum format -t template >&2; 70 | local input=${input:-$(echo $newest_file)}; 71 | else 72 | echo '{{ Bold "[+] Input prompt" }}' | gum format -t template >&2; 73 | local input=${input:-$(echo $(gum input --char-limit=4000 --placeholder="Type something here, just ask me!" --width="$(($COLUMNS-5))" --header="I'm an AI use me wisely!" --header.italic --header.border="rounded" --header.foreground="50" ) )}; 74 | fi 75 | 76 | echo $input > $promptg >&2; 77 | 78 | #-------------------------------------x 79 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Docker to interact with sgpt..." --\ 80 | docker run --rm --env OPENAI_API_KEY -v gpt-cache:/tmp/shell_gpt ghcr.io/ther1d/shell_gpt --no-animation --chat "$session" "$input" > "$codeg"; 81 | 82 | #-------------------------------------x 83 | 84 | local output=$(cat $codeg | tr -d '\n') >&2; 85 | 86 | if [ -z "$output" ]; 87 | then 88 | echo '{{ Bold "Open.ai servers are probably down or unreachable, try again..." }}' | gum format -t template >&2; 89 | return 1; 90 | fi 91 | 92 | gum style "INPUT: saved at $promptg" "$input" "OUTPUT: saved at $codeg" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 93 | 94 | #print formatted code 95 | cat $codeg | gum format -t code 96 | 97 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 98 | 99 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read output?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 100 | && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $codeg; 101 | 102 | echo '{{ Bold "[+] sgpt OK" }}' | gum format -t template >&2; 103 | 104 | echo '{{ Bold "[?] What now? press ESC to exit." }}' | gum format -t template >&2; 105 | echo ' ' >&2; 106 | 107 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "edit output code in glow" "edit input text in glow" "help" "contribute to aiyu"); 108 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="p2c" --height=9); 109 | [[ "$CHOICE" == "edit output code in glow" ]] && cp $codeg "${codeg::-4}.md" && glow "/dev/shm/"; 110 | [[ "$CHOICE" == "edit input text in glow" ]] && cp $promptg "${promptg::-4}.md" && glow "/dev/shm/"; 111 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 112 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, thank you for making $(gum style --bold "aiyu") is the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 113 | 114 | return 1; 115 | } 116 | else 117 | echo '{{ Color "50" "0" " p2c-sgpt is set on the system." }}' | gum format -t template >&2; 118 | fi 119 | fi 120 | 121 | p2c-sgpt "$1"; 122 | } 123 | else 124 | echo '{{ Bold "p2c is set on the system" }}' | gum format -t template >&2; 125 | fi 126 | -------------------------------------------------------------------------------- /m2t: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | lang=${lang:-$(echo ${LANG:0:2})}; 6 | 7 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 8 | 9 | 10 | textw="/dev/shm/textw_$session.txt" 11 | audiow="/dev/shm/audiow_$session.mp3" 12 | 13 | input="" 14 | output="" 15 | 16 | if ! type m2a 2>/dev/null 1>&2; 17 | then 18 | m2t () 19 | { 20 | if ! python3 -c "import pvrecorder" 2>/dev/null 1>&2; 21 | then 22 | echo "PV_Recorder is not installed on your system. Install it: pip3 install pvrecorder and re-try" >&2; 23 | echo "m2a-pvrecorder is disabled" >&2; 24 | elif ! command -v gum --version 2>/dev/null 1>&2; 25 | then 26 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 27 | else 28 | if ! type m2a-pvrecorder 2>/dev/null 1>&2; 29 | then 30 | m2a-pvrecorder () 31 | { 32 | 33 | echo '{{ Bold "[*] session: '$session' " }}' | gum format -t template >&2; 34 | 35 | #set -uo pipefail; 36 | 37 | echo '{{ Bold "[!] record started" }}' | gum format -t template >&2; 38 | 39 | local start=$SECONDS; 40 | 41 | #local output="$1"; 42 | local output=${output:-$(echo $audiow)}; 43 | 44 | gum style "using microphone for audio recording." "INPUT: microphone" "OUTPUT: audio saved at $output" "DEVICE: default mic" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 45 | 46 | # subtitle to text: https://github.com/Picovoice/pvrecorder/tree/main/sdk/python 47 | 48 | wget -qO - https://raw.githubusercontent.com/Picovoice/pvrecorder/main/sdk/python/demo.py > /dev/shm/recorder.py 49 | echo '{{ Bold "[+] Recording has started! stop it with CTRL+C" }}' | gum format -t template >&2; 50 | 51 | 52 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "recording with default mic..." --\ 53 | python3 /dev/shm/recorder.py --output_path $output; 54 | 55 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 56 | echo '{{ Bold "[+] recorder OK" }}' | gum format -t template >&2; 57 | 58 | echo ' ' >&2; 59 | 60 | } 61 | else 62 | echo '{{ Bold "m2a-pvrecorder is set on the system" }}' | gum format -t template >&2; 63 | fi 64 | fi 65 | 66 | if ! command -v whisper-ctranslate2 2>/dev/null 1>&2; 67 | then 68 | echo "whisper-ctranslate2 is not installed on your system. Install it: pip install -U whisper-ctranslate2" >&2; 69 | echo "if it's your first time whisper is going to install a medium sized model (2.85 GB)" 70 | echo "a2t is disabled" >&2; 71 | elif ! command -v gum --version 2>/dev/null 1>&2; 72 | then 73 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 74 | else 75 | if ! type a2t-whisp 2>/dev/null 1>&2; 76 | then 77 | a2t-whisp () 78 | { 79 | 80 | echo '{{ Bold "[!] whisper subtitles started" }}' | gum format -t template >&2; 81 | 82 | if [ -z ${OPENAI_API_KEY+x} ]; then echo '{{ Bold "[!] OPENAI_API_KEY not set! type: export OPENAI_API_KEY=\"your-key-here\" " }}' | gum format -t template >&2; return 1; fi 83 | 84 | local start=$SECONDS; 85 | 86 | local formatsub=${formatsub:-$(echo "txt")}; 87 | local model=${model:-$(echo "medium")}; 88 | #if input text exis then set it as input, if not select it 89 | 90 | #local input="$1"; 91 | 92 | #select the lastly created file.mp3 (1 minute old) located in /dev/shm/ OR select a local .mp3 file 93 | local newest_file=""; 94 | local newest_file=$(find /dev/shm/ -cmin -1 -type f -name "*.mp3" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 95 | if [ -n "$newest_file" ]; then 96 | echo '{{ Italic "[!] using most recent recording " }}' | gum format -t template >&2; 97 | local input=${input:-$(echo $newest_file)}; 98 | else 99 | echo '{{ Bold "[+] Select a mp3 file. Use keyboard arrows < > to traverse directories, up or down arrows to move in the directory." }}' | gum format -t template >&2; 100 | local input=$(gum file $PWD); 101 | fi 102 | 103 | #output definition 104 | local output="$1"; 105 | local output=${output:-$(echo $textw)}; 106 | #local tmpsrt=$(basename $subw); 107 | #local tmptxt=$(basename $output); 108 | 109 | gum style "INPUT audio located at: $input" "INput audio language: auto" "OUTPUT text saved at $output" "OUTput language: auto" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 110 | 111 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Whisper for subtitles creation... this can take a short while" --\ 112 | whisper-ctranslate2 $input --output_format $formatsub --task transcribe --compute_type int8 --output_dir /dev/shm/ ; 113 | #choose best model 114 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 115 | 116 | #rename subtitle file to the output name 117 | local namesrt=$(basename $input); 118 | mv "/dev/shm/${namesrt%.*}.$formatsub" "$textw"; 119 | 120 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read text?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 121 | && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $output; 122 | echo '{{ Bold "[+] subtitles OK" }}' | gum format -t template >&2; 123 | 124 | echo '{{ Bold "[?] what now? press ESC to exit." }}' | gum format -t template >&2; 125 | echo ' ' >&2; 126 | 127 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "edit output text in glow" "play recorded audio" "help" "contribute to aiyu"); 128 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="m2t" --height=9); 129 | [[ "$CHOICE" == "edit output text in glow" ]] && cp $textw "${textw::-4}.md" && glow "/dev/shm/"; 130 | [[ "$CHOICE" == "play recorded audio" ]] && ffplay -nodisp -autoexit -loglevel fatal $audiow; 131 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 132 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, thank you for making $(gum style --bold "aiyu") is the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 133 | 134 | 135 | } 136 | 137 | else 138 | echo "m2t is set on the system. To use it: m2t \"output.mp3\" " >&2; 139 | fi 140 | fi 141 | 142 | m2a-pvrecorder && a2t-whisp "$1"; 143 | 144 | } 145 | else 146 | echo '{{ Bold "m2t is set on the system" }}' | gum format -t template >&2; 147 | fia -------------------------------------------------------------------------------- /t2t: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | #lang=${lang:-$(echo ${LANG:0:2})}; 6 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 7 | 8 | textg="/dev/shm/textg_$session.txt" 9 | tradg="/dev/shm/tradg_$session.txt" 10 | 11 | 12 | if ! type t2t 2>/dev/null 1>&2; 13 | then 14 | t2t () 15 | { 16 | 17 | if ! command -v docker --version 2>/dev/null 1>&2; 18 | then 19 | echo "trad is not installed on your system. https://github.com/soimort/translate-shell " >&2; 20 | echo "t2t-ttrans is disabled" >&2; 21 | elif ! command -v gum --version 2>/dev/null 1>&2; 22 | then 23 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 24 | else 25 | if ! type t2t-ttrans 2>/dev/null 1>&2; 26 | then 27 | t2t-ttrans () 28 | { 29 | 30 | echo '{{ Bold "[!] traduction started" }}' | gum format -t template >&2; 31 | 32 | if [ -z ${OPENAI_API_KEY+x} ]; then echo '{{ Bold "[!] OPENAI_API_KEY not set! type: export OPENAI_API_KEY=\"your-key-here\" " }}' | gum format -t template >&2; return 1; fi 33 | 34 | local start=$SECONDS; 35 | local input="$2"; 36 | 37 | local newest_file=""; 38 | newest_file=$(find /dev/shm/ -type f -cmin -1 -size +0 -regextype sed -regex ".*\(t\|s\)*.\(txt\|srt\)" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 39 | if [ -n "$newest_file" ]; then 40 | echo '{{ Bold "[!] most recent text file --> '$newest_file'" }}' | gum format -t template >&2; 41 | local input=${input:-$(echo $newest_file)}; 42 | else 43 | echo '{{ Bold "[+] Input prompt" }}' | gum format -t template >&2; 44 | local input=${input:-$(echo $(gum input --char-limit=4000 --placeholder="Type something here, just ask me!" --width="$(($COLUMNS-5))" ) )}; 45 | fi 46 | 47 | local output="$tradg"; 48 | 49 | local langto="$1"; 50 | local langto=${langto:-$(echo "en")}; 51 | local langfrom=${langfrom:-$(echo "auto")}; #sould autodetect language 52 | 53 | gum style "input text: $input" "language from: $langfrom" "output: $output" "language to: $langto" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 54 | 55 | local intrad=""; 56 | intrad=$(<"$input"); 57 | echo $intrad > $textg >&2; 58 | 59 | #------------------------------------------------------------# 60 | #using https://github.com/soimort/translate-shell 61 | gum spin --spinner points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using trad for translation generation..." -- sleep 2 62 | docker run --rm -it soimort/translate-shell -shell -brief -w 10 :"$langto" "$intrad" | tail -n +3 > $output; 63 | #------------------------------------------------------------# 64 | 65 | # prints to terminal 66 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 67 | 68 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read translation?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 69 | && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $output; 70 | 71 | echo '{{ Bold "[+] translation OK" }}' | gum format -t template >&2; 72 | echo '{{ Bold "[?] What now? press ESC to exit." }}' | gum format -t template >&2; 73 | echo ' ' >&2; 74 | 75 | 76 | while read -r -n1 key 77 | do 78 | # if input == ESC key 79 | if [[ $key == $'\e' ]]; 80 | then 81 | break; 82 | fi 83 | 84 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "edit output translation in glow" "edit input text in glow" "help" "contribute to aiyu"); 85 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="t2t" --height=18); 86 | [[ "$CHOICE" == "edit output translation in glow" ]] && cp $tradg "${tradg::-4}.md" && glow "/dev/shm/"; 87 | [[ "$CHOICE" == "edit input text in glow" ]] && cp $input "${input::-4}.md" && glow "/dev/shm/"; 88 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 89 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, thank you for making $(gum style --bold "aiyu") is the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 90 | 91 | done; 92 | 93 | } 94 | else 95 | echo "t2t-ttrans is set on the system.To use it: \"t2t-ttrans lang file.txt \" " >&2; 96 | fi 97 | fi 98 | 99 | t2t-ttrans "$1" "$2"; 100 | #t2t-dtrans "$1" "$2"; 101 | } 102 | else 103 | echo '{{ Bold "t2t is set on the system" }}' | gum format -t template >&2; 104 | fi 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | #if ! type t2t 2>/dev/null 1>&2; 122 | #then 123 | # t2t () 124 | # { 125 | # if ! command -v deepl -V 2>/dev/null 1>&2; 126 | # then 127 | # echo "deppl is not installed on your system. Install it: pip install deppl-cli" >&2; 128 | # echo "t2t-deepl is disabled" >&2; 129 | # else 130 | # if ! type t2t-dtrans 2>/dev/null 1>&2; 131 | # then 132 | # t2t-dtrans () 133 | # { 134 | # 135 | # local input="$2"; 136 | # local newest_file=""; #=$(stat -c '%Y %n' /dev/shm/*.mp3 | sort -nr | head -n1 | cut -d' ' -f2); 137 | # local txt_file=$(ls -t /dev/shm/*.txt | head -1) ; # find newest *.mp3 file 138 | # local srt_file=$(ls -t /dev/shm/*.srt | head -1); # find newest *.xyz file 139 | 140 | # if [[ $(stat -c %Y "$txt_file") -gt $(stat -c %Y "$srt_file") ]]; then 141 | # newest_file="$txt_file"; 142 | # else 143 | # newest_file="$srt_file"; 144 | # fi 145 | # 146 | # 147 | # local output="$tradg"; 148 | 149 | 150 | #"valid languages of `--fr`: 151 | #{'fi', 'cs', 'lv', 'nl', 'el', 'auto', 'ru', 'da', 'sv', 'it', 'uk', 'zh', 'ko', 'et', 'de', 'en', 'es', 'bg', 'lt', 'ja', 'pl', 'tr', 'id', 'sk', 'sl', 'hu', 'fr', 'ro', 'pt'} 152 | #valid languages of `--to`: 153 | #{'fi', 'cs', 'lv', 'nl', 'lt', 'ja', 'el', 'pl', 'ru', 'tr', 'da', 'sv', 'pt', 'id', 'it', 'sk', 'sl', 'hu', 'fr', 'uk', 'zh', 'ko', 'et', 'de', 'en', 'ro', 'es', 'bg'} " 154 | 155 | # #langfrom="$3" 156 | # langto="$1" 157 | # 158 | # langto=${langto:-$(echo "en")}; 159 | # langfrom=${langfrom:-$(echo "auto")}; #sould autodetect language 160 | # #time=${time:-$(echo "5000")}; #timeout interval (default: 5000) 161 | # char=$(cat $input | wc -m) #chars count 162 | # 163 | # if [ -z "$input" ]; 164 | # then 165 | # echo "No input" >&2; 166 | # return 1; 167 | # fi 168 | # echo "using deepl for translation generation" >&2; 169 | 170 | # gum style "input text: $input" "language from: $langfrom" "output: $output" "language to: $langto" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 171 | # 172 | # gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using deepl for translation generation..." --\ 173 | # cat $input | tr -d '[:cntrl:]' | deepl -s --to "$langto" | tr -d '[:cntrl:]' > $output #same as: deepl -f $input . 174 | ## 175 | # echo "ok 1" 176 | # gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read translation?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 177 | # && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $output; 178 | # 179 | # echo "[OK] deepl text to translation done."; >&2; 180 | # echo "[=] text used to create voice archived at: $input " >&2; 181 | # echo "[+] translated text saved at: $output "; >&2; 182 | # } 183 | # else 184 | # echo "t2t-dtrans is set on the system.To use it: \"t2t-dtrans text.txt trans.txt \" " >&2; 185 | # fi 186 | # fi 187 | 188 | 189 | -------------------------------------------------------------------------------- /t2tr: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | lang=${lang:-$(echo ${LANG:0:2})}; 6 | 7 | 8 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 9 | 10 | 11 | 12 | 13 | audiow="/dev/shm/audiow_$session.mp3" 14 | voicew="/dev/shm/voicew_$session.mp3" 15 | textw="/dev/shm/textw_$session.txt" 16 | tradw="/dev/shm/tradw_$session.txt" 17 | subw="/dev/shm/subw_$session.srt" 18 | 19 | 20 | voiceg="/dev/shm/vocieg_$session.mp3" 21 | audiog="/dev/shm/audiog_$session.mp3" 22 | textg="/dev/shm/textg_$session.txt" 23 | askg="/dev/shm/askg_$session.txt" 24 | tradg="/dev/shm/tradg_$session.txt" 25 | 26 | subg="/dev/shm/subg_$session.srt" 27 | input="" 28 | output="" 29 | tmp="" 30 | 31 | if ! type t2tr 2>/dev/null 1>&2; 32 | then 33 | t2tr () 34 | { 35 | if ! command -v deepl -V 2>/dev/null 1>&2; 36 | then 37 | echo "deppl is not installed on your system. Install it: pip install deppl-cli" >&2; 38 | echo "o-deepl is disabled" >&2; 39 | else 40 | if ! type o-dtrans 2>/dev/null 1>&2; 41 | then 42 | o-dtrans () 43 | { 44 | 45 | local input="$2"; 46 | local newest_file=""; #=$(stat -c '%Y %n' /dev/shm/*.mp3 | sort -nr | head -n1 | cut -d' ' -f2); 47 | local txt_file=$(ls -t /dev/shm/*.txt | head -1) ; # find newest *.mp3 file 48 | local srt_file=$(ls -t /dev/shm/*.srt | head -1); # find newest *.xyz file 49 | 50 | if [[ $(stat -c %Y "$txt_file") -gt $(stat -c %Y "$srt_file") ]]; then 51 | newest_file="$txt_file"; 52 | else 53 | newest_file="$srt_file"; 54 | fi 55 | 56 | 57 | local output="$tradg"; 58 | 59 | 60 | #"valid languages of `--fr`: 61 | #{'fi', 'cs', 'lv', 'nl', 'el', 'auto', 'ru', 'da', 'sv', 'it', 'uk', 'zh', 'ko', 'et', 'de', 'en', 'es', 'bg', 'lt', 'ja', 'pl', 'tr', 'id', 'sk', 'sl', 'hu', 'fr', 'ro', 'pt'} 62 | #valid languages of `--to`: 63 | #{'fi', 'cs', 'lv', 'nl', 'lt', 'ja', 'el', 'pl', 'ru', 'tr', 'da', 'sv', 'pt', 'id', 'it', 'sk', 'sl', 'hu', 'fr', 'uk', 'zh', 'ko', 'et', 'de', 'en', 'ro', 'es', 'bg'} " 64 | 65 | #langfrom="$3" 66 | langto="$1" 67 | 68 | langto=${langto:-$(echo "en")}; 69 | langfrom=${langfrom:-$(echo "auto")}; #sould autodetect language 70 | #time=${time:-$(echo "5000")}; #timeout interval (default: 5000) 71 | char=$(cat $input | wc -m) #chars count 72 | 73 | if [ -z "$input" ]; 74 | then 75 | echo "No input" >&2; 76 | return 1; 77 | fi 78 | echo "using deepl for translation generation" >&2; 79 | 80 | gum style "input text: $input" "language from: $langfrom" "output: $output" "language to: $langto" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 81 | 82 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using deepl for translation generation..." --\ 83 | cat $input | tr -d '[:cntrl:]' | deepl -s --to "$langto" | tr -d '[:cntrl:]' > $output #same as: deepl -f $input . 84 | 85 | echo "ok 1" 86 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read translation?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 87 | && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $output; 88 | 89 | echo "[OK] deepl text to translation done."; >&2; 90 | echo "[=] text used to create voice archived at: $input " >&2; 91 | echo "[+] translated text saved at: $output "; >&2; 92 | } 93 | else 94 | echo "o-dtrans is set on the system.To use it: \"o-dtrans text.txt trans.txt \" " >&2; 95 | fi 96 | fi 97 | 98 | if ! command -v docker --version 2>/dev/null 1>&2; 99 | then 100 | echo "trad is not installed on your system. https://github.com/soimort/translate-shell " >&2; 101 | echo "o-ttrans is disabled" >&2; 102 | elif ! command -v gum --version 2>/dev/null 1>&2; 103 | then 104 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 105 | else 106 | if ! type o-ttrans 2>/dev/null 1>&2; 107 | then 108 | o-ttrans () 109 | { 110 | 111 | echo '{{ Bold "[!] traduction started" }}' | gum format -t template >&2; 112 | 113 | if [ -z ${OPENAI_API_KEY+x} ]; then echo '{{ Bold "[!] OPENAI_API_KEY not set! type: export OPENAI_API_KEY=\"your-key-here\" " }}' | gum format -t template >&2; return 1; fi 114 | 115 | local start=$SECONDS; 116 | 117 | local input="$2"; 118 | 119 | local newest_txtfile=""; 120 | local newest_txtfile=$(find /dev/shm/ -cmin -1 -type f -name "*.txt" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 121 | if [ -n "$newest_txtfile" ]; then 122 | echo '{{ Bold "[!] most recent text file --> '$newest_file'" }}' | gum format -t template >&2; 123 | local input=${input:-$(echo $newest_txtfile)}; 124 | fi 125 | 126 | local newest_srtfile=""; 127 | local newest_srtfile=$(find /dev/shm/ -cmin -1 -type f -name "*.txt" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 128 | if [ -n "$newest_srtfile" ]; then 129 | echo '{{ Bold "[!] most recent subtitle file --> '$newest_file'" }}' | gum format -t template >&2; 130 | local input=${input:-$(echo $newest_srtfile)}; 131 | fi 132 | 133 | if [ -z "$input" ]; then 134 | echo '{{ Bold "[+] Select a mp3 file. Use keyboard arrows < > to traverse directories, up or down arrows to move in the directory." }}' | gum format -t template >&2; 135 | local input=${input:-$(echo $(gum file $PWD))}; 136 | fi 137 | 138 | local output="$tradg"; 139 | 140 | local langto="$1" 141 | 142 | local langto=${langto:-$(echo "en")}; 143 | local langfrom=${langfrom:-$(echo "auto")}; #sould autodetect language 144 | 145 | gum style "input text: $input" "language from: $langfrom" "output: $output" "language to: $langto" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 146 | 147 | local intrad=$(<"$input"); 148 | 149 | #using https://github.com/soimort/translate-shell 150 | gum spin --spinner points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using trad for translation generation..." -- sleep 2 151 | docker run --rm -it soimort/translate-shell -shell -brief -w 10 :"$langto" "$intrad" | tail -n +3 > $output; 152 | 153 | 154 | 155 | # prints to terminal 156 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 157 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read translation?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 158 | && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $output; 159 | echo '{{ Bold "[+] translation OK" }}' | gum format -t template >&2; 160 | echo '{{ Bold "[?] What now? press ESC to exit." }}' | gum format -t template >&2; 161 | echo ' ' >&2; 162 | 163 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "edit output translation in glow" "edit input text in glow" "help" "contribute to aiyu"); 164 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="t2tr" --height=9); 165 | [[ "$CHOICE" == "edit output translation in glow" ]] && cp $tradg "${tradg::-4}.md" && glow "/dev/shm/"; 166 | [[ "$CHOICE" == "edit input text in glow" ]] && cp $input "${input::-4}.md" && glow "/dev/shm/"; 167 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 168 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, thank you for making $(gum style --bold "aiyu") is the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 169 | 170 | } 171 | else 172 | echo "o-ttrans is set on the system.To use it: \"o-ttrans lang file.txt \" " >&2; 173 | fi 174 | fi 175 | 176 | o-ttrans "$1" "$2"; 177 | #o-dtrans "$1" "$2"; 178 | } 179 | else 180 | echo '{{ Bold "t2tr is set on the system" }}' | gum format -t template >&2; 181 | fi 182 | -------------------------------------------------------------------------------- /t2a: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | 6 | lang=${lang:-$(echo ${LANG:0:2})}; 7 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 8 | 9 | 10 | audiow="/dev/shm/audiow_$session.mp3" 11 | voicew="/dev/shm/voicew_$session.mp3" 12 | textw="/dev/shm/textw_$session.txt" 13 | tradw="/dev/shm/tradw_$session.txt" 14 | subw="/dev/shm/subw_$session.srt" 15 | 16 | 17 | voiceg="/dev/shm/vocieg_$session.mp3" 18 | audiog="/dev/shm/audiog_$session.mp3" 19 | textg="/dev/shm/textg_$session.txt" 20 | askg="/dev/shm/askg_$session.txt" 21 | subg="/dev/shm/subg_$session.srt" 22 | input="" 23 | output="" 24 | tmp="" 25 | 26 | #gui 27 | #-s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Docker to interact with sgpt..." --\ 28 | #--show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" 29 | #foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1" 30 | #--foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1 31 | 32 | #ffmpeg 33 | #filter=filter.rnn && wget -qO $filter https://raw.githubusercontent.com/GregorR/rnnoise-models/master/somnolent-hogwash-2018-09-01/sh.rnnn 34 | #advanced-audiot="atempo=1.4,dialoguenhance,arnndn=m=$filter,volume=1.3" 35 | 36 | 37 | if ! type t2a 2>/dev/null 1>&2; 38 | then 39 | t2a () 40 | { 41 | 42 | if ! command -v docker --version 2>/dev/null 1>&2; 43 | then 44 | echo " Gum docker is not installed on your system. Install it: https://docs.docker.com/engine/install and re-try" >&2; 45 | echo "t2a-sgpt is disabled" >&2; 46 | elif ! command -v gum --version 2>/dev/null 1>&2; 47 | then 48 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 49 | echo "t2a-sgpt is disabled" >&2; 50 | else 51 | if ! type t2a-sgpt 2>/dev/null 1>&2; 52 | then 53 | 54 | echo '{{ Bold "[*] language: '$lang'" }}' | gum format -t template >&2; 55 | echo '{{ Bold "[*] session: '$session' " }}' | gum format -t template >&2; 56 | 57 | t2a-sgpt () 58 | { 59 | 60 | 61 | echo '{{ Bold "[!] sgpt started" }}' | gum format -t template >&2; 62 | 63 | 64 | 65 | local input="$1"; 66 | #takes function input or if empty askgs for inputs 67 | local input=${input:-$(echo $(gum input --char-limit=4000 --placeholder="Type something here, just askg me!" --width="$(($COLUMNS-5))" --header="I'm an AI use me wisely!" --header.italic --header.border="rounded" --header.foreground="50" ) )}; 68 | 69 | if [ -z "$input" ]; 70 | then 71 | echo "No input" >&2; 72 | return 1; 73 | fi 74 | 75 | echo $input > $askg >&2; 76 | 77 | 78 | #-------------------------------------x 79 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Docker to interact with sgpt..." --\ 80 | docker run --rm --env OPENAI_API_KEY -v gpt-cache:/tmp/shell_gpt ghcr.io/ther1d/shell_gpt --no-animation --chat "$session" "$input" > "$textg"; 81 | 82 | 83 | 84 | 85 | #-------------------------------------x 86 | local output=$(cat $textg | tr -d '\n') >&2; 87 | 88 | if [ -z "$output" ]; 89 | then 90 | echo '{{ Bold "Open.ai servers are probably down or unreachable, try again..." ' | gum format -t template >&2; 91 | return 1; 92 | fi 93 | 94 | gum style "INPUT: saved at $askg" "$input" "OUTPUT: saved at $textg" "$output" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 95 | 96 | 97 | if command -v glow --version 2>/dev/null 1>&2; 98 | then 99 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read output?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ && glow stash $output -m "$input"; 100 | fi 101 | 102 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read output?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 103 | && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $textg; 104 | 105 | echo '{{ Bold "[+] sgpt started" }}' | gum format -t template >&2; 106 | } 107 | else 108 | echo '{{ Color "50" "0" " t2a-sgpt is set on the system." }}' | gum format -t template >&2; 109 | fi 110 | fi 111 | 112 | 113 | if ! command -v gtts-cli --version 2>/dev/null 1>&2; 114 | then 115 | echo '{{ Color "99" "0" " gtts-cli is not intalled on your system, please install it and re-try" }}' | gum format -t template >&2; 116 | echo "t2a-gtts is disabled" >&2; 117 | else 118 | if ! type t2a-gtts 2>/dev/null 1>&2; 119 | then 120 | t2a-gtts () 121 | { 122 | echo '{{ Bold "[!] gtts started" }}' | gum format -t template >&2; 123 | 124 | local input="$1"; 125 | [ -f $textg ] && local input=${input:-$(echo $textg)} || local input=${input:-$(echo $(gum file $PWD))}; 126 | 127 | local output="$2"; 128 | local output="$voiceg"; 129 | 130 | if [ -z "$input" ]; 131 | then 132 | echo "No input" >&2; 133 | return 1; 134 | fi 135 | 136 | #desc 137 | gum style "using gtts for voiceg generation." "INPUT: saved at $input" "OUTPUT: audiog saved at $voiceg" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 138 | 139 | #spinner + gtts command 140 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using gtts to transform textg to audiog..." --\ 141 | gtts-cli -l ${lang} -f $textg --output $output; 142 | echo '{{ Bold "[+] gtts OK" }}' | gum format -t template >&2; 143 | } 144 | else 145 | echo '{{ Bold "t2a-gtts is set on the system" }}' | gum format -t template >&2; 146 | fi 147 | fi 148 | 149 | if ! command -v ffmpeg --version 2>/dev/null 1>&2; 150 | then 151 | echo "ffmpeg is not installed on your system. Install it and re-try" >&2; 152 | echo "t2a-ffmpeg is disabled" >&2; 153 | else 154 | if ! type t2a-ffmpeg 2>/dev/null 1>&2; 155 | then 156 | t2a-ffmpeg () 157 | { 158 | echo '{{ Bold "[!] ffmpeg started" }}' | gum format -t template >&2; 159 | 160 | local input="$1"; 161 | [ -f $voiceg ] && local input=${input:-$(echo $voiceg)} || local input=${input:-$(echo $(gum file $PWD))}; 162 | 163 | local output="$2"; 164 | local output=$voiceg 165 | 166 | if [ -z "$input" ]; 167 | then 168 | echo "No input" >&2; 169 | return 1; 170 | fi 171 | 172 | gum style "using ffmpeg for audiog enanchemnt and output creation." "INPUT: audiog saved at $input" "OUTPUT: audiog saved at $output" "FILTER: audiog filter at $filter" "SESSION: $session" "SPEED: 1.4" "VOLUME: 1.3" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 173 | ffmpeg -y -i $input -loglevel fatal -af "atempo=1.4,dialoguenhance,arnndn=m=$filter,volume=1.3" $output; 174 | echo '{{ Bold "[+] ffmpeg OK" }}' | gum format -t template >&2; 175 | 176 | 177 | echo '{{ Bold "DONE! what now?" }}' | gum format -t template >&2; 178 | 179 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "play audio output" "edit text output in glow" "help" "contribute to aiyu"); 180 | 181 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="t2a" --height=9); 182 | [[ "$CHOICE" == "play audio output" ]] && ffplay -nodisp -autoexit -loglevel fatal $output; 183 | [[ "$CHOICE" == "edit text output in glow" ]] && cp $textg "${textg::-4}.md" && glow "/dev/shm/"; 184 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 185 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, $(gum style --bold "aiyu") is the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 186 | 187 | } 188 | else 189 | echo '{{ Bold "t2a-ffmpeg is set on the system" }}' | gum format -t template >&2; 190 | fi 191 | fi 192 | 193 | t2a-sgpt "$1" && t2a-gtts && t2a-ffmpeg; 194 | 195 | 196 | } 197 | else 198 | echo '{{ Bold "t2a is set on the system" }}' | gum format -t template >&2; 199 | fi 200 | -------------------------------------------------------------------------------- /p2a: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | 6 | #lang=${lang:-$(echo ${LANG:0:2})}; 7 | session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 8 | filter=filter.rnn && wget -qO $filter https://raw.githubusercontent.com/GregorR/rnnoise-models/master/somnolent-hogwash-2018-09-01/sh.rnnn 9 | 10 | promptg="/dev/shm/promptg_$session.txt" 11 | voiceg="/dev/shm/vocieg_$session.mp3" 12 | audiog="/dev/shm/audiog_$session.mp3" 13 | textg="/dev/shm/textg_$session.txt" 14 | 15 | #input="" 16 | #output="" 17 | 18 | if ! type p2a 2>/dev/null 1>&2; 19 | then 20 | p2a () 21 | { 22 | 23 | if ! command -v docker --version 2>/dev/null 1>&2; 24 | then 25 | echo " Gum docker is not installed on your system. Install it: https://docs.docker.com/engine/install and re-try" >&2; 26 | echo "p2a-sgpt is disabled" >&2; 27 | elif ! command -v gum --version 2>/dev/null 1>&2; 28 | then 29 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 30 | echo "p2a-sgpt is disabled" >&2; 31 | else 32 | if ! type p2a-sgpt 2>/dev/null 1>&2; 33 | then 34 | 35 | echo '{{ Bold "[*] session: '$session' " }}' | gum format -t template >&2; 36 | 37 | p2a-sgpt () 38 | { 39 | 40 | if [ -z ${OPENAI_API_KEY+x} ]; then echo '{{ Bold "[!] OPENAI_API_KEY not set! type: export OPENAI_API_KEY=\"your-key-here\" " }}' | gum format -t template >&2; return 1; fi 41 | 42 | echo '{{ Bold "[!] sgpt started" }}' | gum format -t template >&2; 43 | 44 | local start=$SECONDS; 45 | local input="$1"; 46 | local output=""; 47 | 48 | #select the lastly created file.txt (1 minute old) located in /dev/shm/ OR input prompt directly 49 | local newest_file=""; 50 | newest_file=$(find /dev/shm/ -type f -cmin -1 -size +0 -regextype sed -regex ".*\(p\|t\)*.txt" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 51 | 52 | if [ -n "$newest_file" ]; then 53 | echo '{{ Bold "[!] most recent text file --> '$newest_file'" }}' | gum format -t template >&2; 54 | local input=${input:-$(echo $newest_file)}; 55 | else 56 | echo '{{ Bold "[+] Input prompt" }}' | gum format -t template >&2; 57 | local input=${input:-$(echo $(gum input --char-limit=4000 --placeholder="Type something here, just ask me!" --width="$(($COLUMNS-5))" --header="I'm an AI use me wisely!" --header.italic --header.border="rounded" --header.foreground="50" ) )}; 58 | fi 59 | 60 | #-------------------------------------x 61 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Docker to interact with sgpt..." --\ 62 | docker run --rm --env OPENAI_API_KEY -v gpt-cache:/tmp/shell_gpt ghcr.io/ther1d/shell_gpt --no-animation --chat "$session" "$input" > "$textg"; 63 | #-------------------------------------x 64 | 65 | #saves input question to promptg file 66 | echo $input > $promptg >&2; 67 | #load output variable with generated text 68 | output=$(cat $textg | tr -d '\n') >&2; 69 | 70 | if [ -z "$output" ]; 71 | then 72 | echo '{{ Bold "Open.ai servers are probably down or unreachable, try again... make sure you have you API key is usable: https://platform.openai.com/account/usage " ' | gum format -t template >&2; 73 | return 1; 74 | fi 75 | 76 | #context 77 | gum style "INPUT: saved at $promptg" " " "$input" "OUTPUT: saved at $textg" " " "$output" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 78 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 79 | 80 | #pager 81 | gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read output?" --timeout=10s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 82 | && gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $textg; 83 | 84 | echo '{{ Bold "[+] sgpt OK" }}' | gum format -t template >&2; 85 | 86 | } 87 | else 88 | echo '{{ Italic "p2a-sgpt is set on the system." }}' | gum format -t template >&2; 89 | fi 90 | fi 91 | 92 | 93 | if ! command -v gtts-cli --version 2>/dev/null 1>&2; 94 | then 95 | echo '{{ Bold "gtts-cli is not intalled on your system, please install it and re-try" }}' | gum format -t template >&2; 96 | echo "p2a-gtts is disabled" >&2; 97 | else 98 | if ! type p2a-gtts 2>/dev/null 1>&2; 99 | then 100 | p2a-gtts () 101 | { 102 | 103 | echo '{{ Bold "[!] gtts started" }}' | gum format -t template >&2; 104 | 105 | local start=$SECONDS; 106 | 107 | local input=""; 108 | [ -f $textg ] && input=${input:-$(echo $textg)} || input=${input:-$(echo $(gum file $PWD))}; 109 | 110 | local output=""; 111 | output="$voiceg"; 112 | 113 | if [ -z "$input" ]; 114 | then 115 | echo "No input" >&2; 116 | return 1; 117 | fi 118 | 119 | #desc 120 | gum style "using gtts for voice generation." "INPUT: saved at $input" "OUTPUT: audio saved at $voiceg" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 121 | 122 | #spinner + gtts command 123 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using gtts to transform text to audio..." --\ 124 | gtts-cli -f $textg --output $output; 125 | 126 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 127 | 128 | echo '{{ Bold "[+] gtts OK" }}' | gum format -t template >&2; 129 | } 130 | else 131 | echo '{{ Bold "p2a-gtts is set on the system" }}' | gum format -t template >&2; 132 | fi 133 | fi 134 | 135 | if ! command -v ffmpeg --version 2>/dev/null 1>&2; 136 | then 137 | echo "ffmpeg is not installed on your system. Install it and re-try" >&2; 138 | echo "p2a-ffmpeg is disabled" >&2; 139 | else 140 | if ! type p2a-ffmpeg 2>/dev/null 1>&2; 141 | then 142 | p2a-ffmpeg () 143 | { 144 | echo '{{ Bold "[!] ffmpeg started" }}' | gum format -t template >&2; 145 | 146 | local start=$SECONDS; 147 | 148 | local input=""; 149 | [ -f $voiceg ] && input=${input:-$(echo $voiceg)} || input=${input:-$(echo $(gum file $PWD))}; 150 | 151 | local output=""; 152 | local output=$audiog 153 | 154 | if [ -z "$input" ]; 155 | then 156 | echo "No input" >&2; 157 | return 1; 158 | fi 159 | 160 | #context 161 | gum style "using ffmpeg for audio enanchemnt and output creation." "INPUT: voice saved at $input" "OUTPUT: audio saved at $output" "FILTER: audio filter at $filter" "SESSION: $session" "SPEED: 1.4" "VOLUME: 1.3" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 162 | ffmpeg -y -i $input -loglevel fatal -af "atempo=1.4,dialoguenhance,arnndn=m=$filter,volume=1.3" $output; 163 | 164 | 165 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 166 | echo '{{ Bold "[+] ffmpeg OK" }}' | gum format -t template >&2; 167 | echo '{{ Bold "DONE! what now?" }}' | gum format -t template >&2; 168 | 169 | while read -r -n1 key 170 | do 171 | # if input == ESC key 172 | if [[ $key == $'\e' ]]; 173 | then 174 | break; 175 | fi 176 | 177 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "play audio output" "edit text output in glow" "help" "contribute to aiyu"); 178 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="p2a" --height=9); 179 | [[ "$CHOICE" == "play audio output" ]] && ffplay -nodisp -autoexit -loglevel fatal $output; 180 | [[ "$CHOICE" == "edit text output in glow" ]] && cp $textg "${textg::-4}.md" && glow "/dev/shm/"; 181 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 182 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, $(gum style --bold "aiyu") is the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 183 | 184 | done; 185 | 186 | } 187 | 188 | else 189 | echo '{{ Bold "p2a-ffmpeg is set on the system" }}' | gum format -t template >&2; 190 | fi 191 | fi 192 | 193 | p2a-sgpt "$1" && p2a-gtts && p2a-ffmpeg; 194 | 195 | 196 | } 197 | else 198 | echo '{{ Bold "p2a is set on the system" }}' | gum format -t template >&2; 199 | fi 200 | -------------------------------------------------------------------------------- /a2a: -------------------------------------------------------------------------------- 1 | # Small but handy functions. For Personal use only. 2 | # Use it at your own risk! 3 | # Author: Gabriele Risso License: Apache 2.0 4 | 5 | #lang=${lang:-$(echo ${LANG:0:2})}; 6 | 7 | filter=filter.rnn && wget -qO $filter https://raw.githubusercontent.com/GregorR/rnnoise-models/master/somnolent-hogwash-2018-09-01/sh.rnnn 8 | 9 | #session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )}; 10 | 11 | session="$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')"; 12 | 13 | audiow="/dev/shm/audiow_$session.mp3" 14 | voicew="/dev/shm/voicew_$session.mp3" 15 | textw="/dev/shm/textw_$session.txt" 16 | tradw="/dev/shm/tradw_$session.txt" 17 | 18 | voiceg="/dev/shm/vocieg_$session.mp3" 19 | audiog="/dev/shm/audiog_$session.mp3" 20 | textg="/dev/shm/textg_$session.txt" 21 | tradg="/dev/shm/tradg_$session.txt" 22 | 23 | 24 | 25 | #a2a $lang = a2a a2a $lang t2a; 26 | 27 | #trap "echo; exit" INT 28 | 29 | if ! type a2a 2>/dev/null 1>&2; 30 | then 31 | a2a () 32 | { 33 | 34 | if ! command -v whisper-ctranslate2 2>/dev/null 1>&2; 35 | then 36 | echo "whisper-ctranslate2 is not installed on your system. Install it: pip install -U whisper-ctranslate2" >&2; 37 | echo "if it's your first time whisper is going to install a medium sized model (2.85 GB)" 38 | echo "a2a is disabled" >&2; 39 | elif ! command -v gum --version 2>/dev/null 1>&2; 40 | then 41 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 42 | else 43 | if ! type a2a-whisp 2>/dev/null 1>&2; 44 | then 45 | a2a-whisp () 46 | { 47 | 48 | if [ -z ${OPENAI_API_KEY+x} ]; then echo '{{ Bold "[!] OPENAI_API_KEY not set! type: export OPENAI_API_KEY=\"your-key-here\" " }}' | gum format -t template >&2; return 1; fi 49 | 50 | echo '{{ Bold "[*] session: '$session' " }}' | gum format -t template >&2; 51 | echo '{{ Bold "[!] whisper subtitles started" }}' | gum format -t template >&2; 52 | 53 | local start=$SECONDS; 54 | local formatsub=${formatsub:-$(echo "txt")}; 55 | local model=${model:-$(echo "medium")}; 56 | #if input text exis then set it as input, if not select it 57 | local input="$1"; 58 | 59 | #select the lastly created file.mp3 (1 minute old) located in /dev/shm/ OR select a local .mp3 file 60 | local newest_file=""; 61 | newest_file=$(find /dev/shm/ -type f -cmin -1 -size +0 -regextype sed -regex ".*\(a\|v\)*.mp3" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 62 | if [ -n "$newest_file" ]; then 63 | echo '{{ Bold "[!] most recent file --> '$newest_file'" }}' | gum format -t template >&2; 64 | input=${input:-$(echo $newest_file)}; 65 | else 66 | echo '{{ Bold "[+] Select a mp3 file. Use keyboard arrows < > to traverse directories, up or down arrows to move in the directory." }}' | gum format -t template >&2; 67 | input=${input:-$(echo $(gum file $PWD) ) }; 68 | fi 69 | 70 | cp -f $input $audiow 2>/dev/null; 71 | 72 | #output definition 73 | local output=""; 74 | local output=${output:-$(echo $textw)}; 75 | #local tmpsrt=$(basename $subw); 76 | #local tmptxt=$(basename $output); 77 | 78 | gum style "INPUT audio located at: $input" "INput audio language: auto" "OUTPUT text saved at $output" "OUTput language: auto" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 79 | 80 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Whisper for text creation... this can take a short while" --\ 81 | whisper-ctranslate2 $input --output_format $formatsub --task transcribe --compute_type int8 --output_dir /dev/shm/ ; 82 | #choose best model 83 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 84 | 85 | #rename subtitle file to the output name 86 | local namesrt=""; 87 | namesrt=$(basename $input); 88 | mv -f "/dev/shm/${namesrt%.*}.$formatsub" "$textw" 2>/dev/null; 89 | 90 | 91 | # subtitle to text: https://github.com/yumstar/sra2aext/blob/main/sra2aext.py 92 | 93 | #context 94 | #gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read text?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 95 | #&& gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $output; 96 | echo '{{ Bold "[+] text OK" }}' | gum format -t template >&2; 97 | 98 | } 99 | 100 | else 101 | echo "a2a-whisp is set on the system. To use it: a2a \"input.mp3\" \"output.mp3\" " >&2; 102 | fi 103 | fi 104 | 105 | if ! command -v docker --version 2>/dev/null 1>&2; 106 | then 107 | echo "trad is not installed on your system. https://github.com/soimort/translate-shell " >&2; 108 | echo "a2a-ttrans is disabled" >&2; 109 | elif ! command -v gum --version 2>/dev/null 1>&2; 110 | then 111 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 112 | else 113 | if ! type a2a-ttrans 2>/dev/null 1>&2; 114 | then 115 | a2a-ttrans () 116 | { 117 | 118 | echo '{{ Bold "[!] traduction started" }}' | gum format -t template >&2; 119 | 120 | if [ -z ${OPENAI_API_KEY+x} ]; then echo '{{ Bold "[!] OPENAI_API_KEY not set! type: export OPENAI_API_KEY=\"your-key-here\" " }}' | gum format -t template >&2; return 1; fi 121 | 122 | local start=$SECONDS; 123 | local input=""; 124 | 125 | local newest_file=""; 126 | newest_file=$(find /dev/shm/ -type f -cmin -1 -size +0 -regextype sed -regex ".*\(t\|s\)*.\(txt\|srt\)" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 127 | if [ -n "$newest_file" ]; then 128 | echo '{{ Bold "[!] most recent text file --> '$newest_file'" }}' | gum format -t template >&2; 129 | input=${input:-$(echo $newest_file)}; 130 | else 131 | echo '{{ Bold "[+] Input prompt" }}' | gum format -t template >&2; 132 | input=${input:-$(echo $textw) }; 133 | fi 134 | 135 | local output="$tradg"; 136 | 137 | local langto="$1"; 138 | local langto=${langto:-$(echo "en")}; 139 | local langfrom=${langfrom:-$(echo "auto")}; #sould autodetect language 140 | 141 | gum style "input text: $input" "language from: $langfrom" "output: $output" "language to: $langto" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 142 | 143 | local intrad=""; 144 | intrad=$(<"$input"); 145 | echo $intrad >| $textg 2>/dev/null; 146 | 147 | #------------------------------------------------------------# 148 | #using https://github.com/soimort/translate-shell 149 | gum spin --spinner points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using trad for translation generation..." -- sleep 2 150 | docker run --rm -it soimort/translate-shell -shell -brief -w 10 :"$langto" "$intrad" | tail -n +3 > $output; 151 | #------------------------------------------------------------# 152 | 153 | # prints to terminal 154 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 155 | 156 | #gum confirm --negative="no" --affirmative="yes, let's read!" "open pager to read translation?" --timeout=15s --selected.foreground="0" --unselected.foreground="44" --selected.italic --unselected.italic --selected.background="50" --prompt.italic --prompt.margin="0 0 0 $(($COLUMNS -29))" \ 157 | #&& gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $output; 158 | 159 | echo '{{ Bold "[+] translation OK" }}' | gum format -t template >&2; 160 | 161 | } 162 | else 163 | echo "a2a-ttrans is set on the system.To use it: \"a2a-ttrans lang file.txt \" " >&2; 164 | fi 165 | fi 166 | 167 | if ! command -v gtts-cli --version 2>/dev/null 1>&2; 168 | then 169 | echo '{{ Bold "gtts-cli is not intalled on your system, please install it and re-try" }}' | gum format -t template >&2; 170 | echo "a2a-gtts is disabled" >&2; 171 | else 172 | if ! type a2a-gtts 2>/dev/null 1>&2; 173 | then 174 | a2a-gtts () 175 | { 176 | 177 | echo '{{ Bold "[!] gtts started" }}' | gum format -t template >&2; 178 | 179 | local start=$SECONDS; 180 | 181 | #local input=""; 182 | #[ -f $textg ] && input=${input:-$(echo $textg)} || input=${input:-$(echo $(gum file $PWD))}; 183 | local input=""; 184 | 185 | #select the lastly created file.mp3 (1 minute old) located in /dev/shm/ OR select a local .mp3 file 186 | local newest_file=""; 187 | newest_file=$(find /dev/shm/ -type f -cmin -1 -size +0 -regextype sed -regex ".*\(t\|s\)*.txt" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 188 | if [ -n "$newest_file" ]; then 189 | echo '{{ Bold "[>] Selecting most recent text file --> '$newest_file'" }}' | gum format -t template >&2; 190 | input=${input:-$(echo $newest_file)}; 191 | else 192 | echo '{{ Bold "[+] Select a .txt file. Use keyboard arrows < > to traverse directories, up or down arrows to move in the directory." }}' | gum format -t template >&2; 193 | input=${input:-$(echo $(gum file $PWD))}; 194 | fi 195 | 196 | local output=""; 197 | output="$voiceg"; 198 | 199 | 200 | #https://gtts.readthedocs.io/en/latest/module.html#localized-accents 201 | local langto="$1"; 202 | langto=${langto:-$(echo "en")}; 203 | 204 | if [ -z "$input" ]; 205 | then 206 | echo "No input" >&2; 207 | return 1; 208 | fi 209 | 210 | #desc 211 | gum style "using gtts for voice generation." "INPUT: saved at $input" "OUTPUT: audio saved at $voiceg" "SESSION: $session" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 212 | 213 | #spinner + gtts command 214 | gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using gtts to transform text to audio..." --\ 215 | gtts-cli -f $input --lang $langto --output $output; 216 | 217 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 218 | echo '{{ Bold "[+] gtts OK" }}' | gum format -t template >&2; 219 | 220 | } 221 | else 222 | echo '{{ Bold "a2a-gtts is set on the system" }}' | gum format -t template >&2; 223 | fi 224 | fi 225 | 226 | if ! command -v ffmpeg --version 2>/dev/null 1>&2; 227 | then 228 | echo "ffmpeg is not installed on your system. Install it and re-try" >&2; 229 | echo "a2a-ffmpeg is disabled" >&2; 230 | elif ! command -v gum --version 2>/dev/null 1>&2; 231 | then 232 | echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2; 233 | else 234 | if ! type a2a-ffmpeg 2>/dev/null 1>&2; 235 | then 236 | a2a-ffmpeg () 237 | { 238 | 239 | if [ -z ${OPENAI_API_KEY+x} ]; then echo '{{ Bold "[!] OPENAI_API_KEY not set! type: export OPENAI_API_KEY=\"your-key-here\" " }}' | gum format -t template >&2; return 1; fi 240 | 241 | echo '{{ Bold "[!] ffmpeg started" }}' | gum format -t template >&2; 242 | 243 | local start=$SECONDS; 244 | local input=""; 245 | 246 | #select the lastly created file.mp3 (1 minute old) located in /dev/shm/ OR select a local .mp3 file 247 | local newest_file=""; 248 | newest_file=$(find /dev/shm/ -type f -cmin -1 -size +0 -regextype sed -regex ".*\(a\|v\)*.mp3" -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -1 | awk '{print $2}'); 249 | if [ -n "$newest_file" ]; then 250 | echo '{{ Bold "[>] Selecting most recent audio file --> '$newest_file'" }}' | gum format -t template >&2; 251 | input=${input:-$(echo $newest_file)}; 252 | else 253 | echo '{{ Bold "[+] Select a mp3 file. Use keyboard arrows < > to traverse directories, up or down arrows to move in the directory." }}' | gum format -t template >&2; 254 | input=${input:-$(echo $(gum file $PWD) )}; 255 | fi 256 | 257 | echo $input >| $audiog 2>/dev/null; 258 | 259 | local output=""; 260 | output=${output:-$(echo $audiog)}; 261 | 262 | gum style "using ffmpeg for audio tune and output creation." "INPUT: audio saved at $input" "OUTPUT: audio saved at $output" "FILTER: audiog filter at $filter" "SESSION: $session" "SPEED: 1.4" "VOLUME: 1.3" --foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"; 263 | 264 | ffmpeg -y -i $input -loglevel fatal -af "atempo=1.4,dialoguenhance,arnndn=m=$filter,volume=1.3" $output; 265 | 266 | echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2; 267 | echo '{{ Bold "[+] ffmpeg OK" }}' | gum format -t template >&2; 268 | echo ' ' >&2; 269 | echo '{{ Bold "[>] DONE! ENTER for more options." }}' | gum format -t template >&2; 270 | echo '{{ Bold "[?] press ESC to exit." }}' | gum format -t template >&2; 271 | 272 | while read -r -n1 key 273 | do 274 | # if input == ESC key 275 | if [[ $key == $'\e' ]]; 276 | then 277 | break; 278 | fi 279 | 280 | #printf '\n'>&2; 281 | CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "play input audio" "play output audio" "help" "contribute to aiyu"); 282 | [[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="a2a" --height=9); 283 | [[ "$CHOICE" == "play input audio" ]] && ffplay -nodisp -autoexit -loglevel fatal $audiow; 284 | [[ "$CHOICE" == "play output audio" ]] && ffplay -nodisp -autoexit -loglevel fatal $output; 285 | [[ "$CHOICE" == "edit output translation in glow" ]] && cp $tradg "${tradg::-4}.md" && glow "/dev/shm/"; 286 | [[ "$CHOICE" == "edit input text in glow" ]] && cp $textw "${textw::-4}.md" && glow "/dev/shm/"; 287 | [[ "$CHOICE" == "help" ]] && glow -p README.md; 288 | [[ "$CHOICE" == "contribute to aiyu" ]] && echo "Great! I thought so, thank you for making $(gum style --bold "aiyu") the best! leave a $(gum style --bold "star") if you like this. Go to: https://github.com/GabrieleRisso/aiyu"; 289 | #printf '\n' >&2; 290 | 291 | done; 292 | 293 | } 294 | else 295 | echo '{{ Bold "a2a-ffmpeg is set on the system" }}' | gum format -t template >&2; 296 | fi 297 | fi 298 | 299 | a2a-whisp "$2" && a2a-ttrans "$1" && a2a-gtts "$1" && a2a-ffmpeg; 300 | } 301 | else 302 | echo '{{ Bold "a2a is set on the system" }}' | gum format -t template >&2; 303 | fi 304 | 305 | --------------------------------------------------------------------------------