-
Notifications
You must be signed in to change notification settings - Fork 0
/
jarvis.sh
executable file
·71 lines (54 loc) · 1.96 KB
/
jarvis.sh
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
#!/bin/bash
ROOT_DIR=$HOME/projects/jarvis
PROMPT_COLOUR='\033[1;34m'
RESPONSE_COLOUR="\e[1;35m"
RESET_COLOUR='\033[0m'
echo -e "${RESPONSE_COLOUR}"
echo "|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|"
echo "| You bellowed, master? |"
echo "| How can I assist? |"
echo "|===========================================================|"
echo "| hint: |"
echo "| |"
echo "| Press Enter to stop recording, |"
echo "| or after you've written your prompt |"
echo "|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|"
echo -e "${RESET_COLOUR}"
read start
while true; do
echo -e "${PROMPT_COLOUR}"
echo -e "\e[4mYou\e[0m"
echo -e "${RESET_COLOUR}"
echo -e -n "${PROMPT_COLOUR}"
arecord -d 600 -q -f cd -t wav -r 44100 > $ROOT_DIR/tmp.wav &
read text_input
pkill arecord
echo -e -n "${RESET_COLOUR}"
if [[ -z $text_input ]]; then
echo "🎤"
echo ""
lame -r $ROOT_DIR/tmp.wav $ROOT_DIR/tmp.mp3 2> /dev/null
api_response=$(curl -s https://api.openai.com/v1/audio/transcriptions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F "file=@$ROOT_DIR/tmp.mp3" \
-F "model=whisper-1")
rm $ROOT_DIR/tmp.mp3
fi
echo -e "${RESPONSE_COLOUR}"
echo -e "\e[4mJarvis\e[0m"
echo -e "${RESET_COLOUR}"
echo -e -n "${RESPONSE_COLOUR}"
if [[ -z $text_input ]]; then
echo -n $api_response | jq -r '.text' | sgpt --chat longrunning | tee $ROOT_DIR/ai-text-response
else
echo -n $text_input | sgpt --chat longrunning | tee $ROOT_DIR/ai-text-response
fi
festival --tts $ROOT_DIR/ai-text-response &
read -sn 1
pkill festival
read -sn 1
echo -e -n "${RESET_COLOUR}"
rm $ROOT_DIR/ai-text-response
rm $ROOT_DIR/tmp.wav
done