-
Notifications
You must be signed in to change notification settings - Fork 0
/
a2sk
77 lines (61 loc) · 3.29 KB
/
a2sk
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
# Small but handy functions. For Personal use only.
# Use it at your own risk!
# Author: Gabriele Risso License: Apache 2.0
session=${session:-$(echo "$(wget -qO - http://frightanic.com/goodies_content/docker-names.php)-$(date '+%Y-%m-%d-%H')" )};
voiceg="/dev/shm/voiceg_$session.mp3"
voicew="/dev/shm/voicew_$session.mp3"
audiog="/dev/shm/audiog_$session.mp3"
input=""
output=""
if ! type a2sk 2>/dev/null 1>&2;
then
a2sk ()
{
if ! command -v ffplay --version 2>/dev/null 1>&2;
then
echo "ffplay is not installed on your system. Install it and re-try" >&2;
echo "a2sk-ffplay 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;
else
if ! type a2sk-ffplay 2>/dev/null 1>&2;
then
a2sk-ffplay ()
{
set -euo pipefail;
echo '{{ Bold "[!] ffplay started" }}' | gum format -t template >&2;
local start=$SECONDS;
local input="$1";
#select the lastly created file.mp3 (1 minute old) located in /dev/shm/ OR select a local .mp3 file
local newest_file="";
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}');
if [ -n "$newest_file" ]; then
echo '{{ Bold "[>] Selecting most recent audio file --> '$newest_file'" }}' | gum format -t template >&2;
local input=${input:-$(echo $newest_file)};
else
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;
local input=$(gum file $PWD);
fi
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";
ffplay -nodisp -autoexit -loglevel fatal $input;
echo '{{ Bold "[t] completed in '$((SECONDS-start))' seconds" }}' | gum format -t template >&2;
echo '{{ Bold "[+] ffplay OK" }}' | gum format -t template >&2;
echo '{{ Bold "[?] What now? press ESC to exit." }}' | gum format -t template >&2;
echo ' ' >&2;
CHOICE=$(gum choose --item.foreground 250 "edit function sourcecode" "play input audio" "help" "contribute to aiyu");
[[ "$CHOICE" == "edit function sourcecode" ]] && $EDITOR $(gum filter --value="a2t" --height=9);
[[ "$CHOICE" == "play input audio" ]] && ffplay -nodisp -autoexit -loglevel fatal $input;
[[ "$CHOICE" == "help" ]] && glow -p README.md;
[[ "$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";
return 1;
}
else
echo '{{ Bold "a2sk-ffplay is set on the system" }}' | gum format -t template >&2;
fi
fi
a2sk-ffplay "$1";
}
else
echo '{{ Bold "a2sk is set on the system" }}' | gum format -t template >&2;
fi