-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht2a
199 lines (147 loc) · 8.72 KB
/
t2a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Small but handy functions. For Personal use only.
# Use it at your own risk!
# Author: Gabriele Risso License: Apache 2.0
lang=${lang:-$(echo ${LANG:0:2})};
session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )};
audiow="/dev/shm/audiow_$session.mp3"
voicew="/dev/shm/voicew_$session.mp3"
textw="/dev/shm/textw_$session.txt"
tradw="/dev/shm/tradw_$session.txt"
subw="/dev/shm/subw_$session.srt"
voiceg="/dev/shm/vocieg_$session.mp3"
audiog="/dev/shm/audiog_$session.mp3"
textg="/dev/shm/textg_$session.txt"
askg="/dev/shm/askg_$session.txt"
subg="/dev/shm/subg_$session.srt"
input=""
output=""
tmp=""
#gui
#-s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Docker to interact with sgpt..." --\
#--show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1"
#foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1"
#--foreground 15 --border-foreground 50 --border rounded --width="$(($COLUMNS -4))" --italic --margin "1 1" --padding "0 1
#ffmpeg
#filter=filter.rnn && wget -qO $filter https://raw.githubusercontent.com/GregorR/rnnoise-models/master/somnolent-hogwash-2018-09-01/sh.rnnn
#advanced-audiot="atempo=1.4,dialoguenhance,arnndn=m=$filter,volume=1.3"
if ! type t2a 2>/dev/null 1>&2;
then
t2a ()
{
if ! command -v docker --version 2>/dev/null 1>&2;
then
echo " Gum docker is not installed on your system. Install it: https://docs.docker.com/engine/install and re-try" >&2;
echo "t2a-sgpt is disabled" >&2;
elif ! command -v gum --version 2>/dev/null 1>&2;
then
echo " gum is not installed on your system. Install it: https://github.com/charmbracelet/gum#installation and re-try" >&2;
echo "t2a-sgpt is disabled" >&2;
else
if ! type t2a-sgpt 2>/dev/null 1>&2;
then
echo '{{ Bold "[*] language: '$lang'" }}' | gum format -t template >&2;
echo '{{ Bold "[*] session: '$session' " }}' | gum format -t template >&2;
t2a-sgpt ()
{
echo '{{ Bold "[!] sgpt started" }}' | gum format -t template >&2;
local input="$1";
#takes function input or if empty askgs for inputs
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" ) )};
if [ -z "$input" ];
then
echo "No input" >&2;
return 1;
fi
echo $input > $askg >&2;
#-------------------------------------x
gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using Docker to interact with sgpt..." --\
docker run --rm --env OPENAI_API_KEY -v gpt-cache:/tmp/shell_gpt ghcr.io/ther1d/shell_gpt --no-animation --chat "$session" "$input" > "$textg";
#-------------------------------------x
local output=$(cat $textg | tr -d '\n') >&2;
if [ -z "$output" ];
then
echo '{{ Bold "Open.ai servers are probably down or unreachable, try again..." ' | gum format -t template >&2;
return 1;
fi
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";
if command -v glow --version 2>/dev/null 1>&2;
then
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";
fi
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))" \
&& gum pager --soft-wrap --border-foreground="86" --help.foreground="200" --show-line-numbers < $textg;
echo '{{ Bold "[+] sgpt started" }}' | gum format -t template >&2;
}
else
echo '{{ Color "50" "0" " t2a-sgpt is set on the system." }}' | gum format -t template >&2;
fi
fi
if ! command -v gtts-cli --version 2>/dev/null 1>&2;
then
echo '{{ Color "99" "0" " gtts-cli is not intalled on your system, please install it and re-try" }}' | gum format -t template >&2;
echo "t2a-gtts is disabled" >&2;
else
if ! type t2a-gtts 2>/dev/null 1>&2;
then
t2a-gtts ()
{
echo '{{ Bold "[!] gtts started" }}' | gum format -t template >&2;
local input="$1";
[ -f $textg ] && local input=${input:-$(echo $textg)} || local input=${input:-$(echo $(gum file $PWD))};
local output="$2";
local output="$voiceg";
if [ -z "$input" ];
then
echo "No input" >&2;
return 1;
fi
#desc
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";
#spinner + gtts command
gum spin -s points --show-output --spinner.foreground="50" --title.bold --spinner.margin="0 1" --title "using gtts to transform textg to audiog..." --\
gtts-cli -l ${lang} -f $textg --output $output;
echo '{{ Bold "[+] gtts OK" }}' | gum format -t template >&2;
}
else
echo '{{ Bold "t2a-gtts is set on the system" }}' | gum format -t template >&2;
fi
fi
if ! command -v ffmpeg --version 2>/dev/null 1>&2;
then
echo "ffmpeg is not installed on your system. Install it and re-try" >&2;
echo "t2a-ffmpeg is disabled" >&2;
else
if ! type t2a-ffmpeg 2>/dev/null 1>&2;
then
t2a-ffmpeg ()
{
echo '{{ Bold "[!] ffmpeg started" }}' | gum format -t template >&2;
local input="$1";
[ -f $voiceg ] && local input=${input:-$(echo $voiceg)} || local input=${input:-$(echo $(gum file $PWD))};
local output="$2";
local output=$voiceg
if [ -z "$input" ];
then
echo "No input" >&2;
return 1;
fi
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";
ffmpeg -y -i $input -loglevel fatal -af "atempo=1.4,dialoguenhance,arnndn=m=$filter,volume=1.3" $output;
echo '{{ Bold "[+] ffmpeg OK" }}' | gum format -t template >&2;
echo '{{ Bold "DONE! what now?" }}' | gum format -t template >&2;
CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "play audio output" "edit text output in glow" "help" "contribute to aiyu");
[[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="t2a" --height=9);
[[ "$CHOICE" == "play audio output" ]] && ffplay -nodisp -autoexit -loglevel fatal $output;
[[ "$CHOICE" == "edit text output in glow" ]] && cp $textg "${textg::-4}.md" && glow "/dev/shm/";
[[ "$CHOICE" == "help" ]] && glow -p README.md;
[[ "$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";
}
else
echo '{{ Bold "t2a-ffmpeg is set on the system" }}' | gum format -t template >&2;
fi
fi
t2a-sgpt "$1" && t2a-gtts && t2a-ffmpeg;
}
else
echo '{{ Bold "t2a is set on the system" }}' | gum format -t template >&2;
fi