-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_robot.sh
executable file
·81 lines (71 loc) · 2.07 KB
/
start_robot.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
72
73
74
75
76
77
78
79
80
#!/bin/bash
#
# https://github.com/francescor/speech-to-chatgpt-to-speech
#
# Simple script that:
# * listen you talking (speech to text)
# * ask ChatGPT, and
# * speech out the answer (speech synthesizer)
#
# Requirements:
# https://espeak.sourceforge.net `yum install espeak`
# https://github.com/ideasman42/nerd-dictation (vosks, sox, xdotool...)
# https://github.com/TheR1D/shell_gpt
# Env variables:
# export OPENAI_API_KEY=XXXXXXXXXXXXX
# export SOX_OPTS="....."
#
# vosks language models in
# ~/.config/nerd-dictation
# set talking language: en,en-us,de,es,it,pt,nl,ru,.
# if you change language then you better translate the below messages
# remember to adapt nerd-ditcation model, too
LANG=en
clear
function say_message() {
echo "ROBOT: $1"
espeak -v $LANG "$1"
}
say_message "Ask me anything. To exit say: STOP"
my_question=""
chat_session=$(openssl rand -base64 5)
while [[ "${my_question::4}" != "stop" ]]; do
while [[ "$my_question" == "" ]]; do
echo
echo "...listening"
my_question=$(nerd-dictation begin --input=SOX --output=STDOUT --defer-output --timeout 2 2> /dev/null)
echo
echo -n "YOU: "
echo $my_question
if [[ "$my_question" == "" ]]; then
say_message "I don't get it, Please repeat"
fi
done
if [[ "${my_question::4}" != "stop" ]]; then
say_message "You said: ${my_question}"
say_message "Say NO if I'm wrong, or just wait"
echo
echo "...listening"
confirmed=$(nerd-dictation begin --input=SOX --output=STDOUT --defer-output --timeout 1 2> /dev/null)
echo
if [[ "${confirmed}" != "" ]]; then
echo -n "YOU: "
echo $confirmed
fi
if [[ "${confirmed::2}" != "no" ]]; then
echo "...asking ChatGPT"
echo
answer=$(sgpt --chat $chat_session "\"${my_question}\"")
echo -n "ChatGPT: "
echo $answer
espeak -v ${LANG}+f5 "\"${answer}\""
my_question=""
echo
say_message "anything else?"
else
say_message "Ok, sorry I did not get it; please repeat!"
my_question=""
fi
fi
done
say_message "Ok, I stop!"