-
Notifications
You must be signed in to change notification settings - Fork 117
/
run_crying_detection.sh
executable file
·61 lines (51 loc) · 1.14 KB
/
run_crying_detection.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
#!/usr/bin/env bash
PREDICTION=1
PLAYING=0
CPT=0
function clean_up {
# Perform program exit housekeeping
echo ""
echo "Thank you for using parenting 2.0"
echo "Good Bye."
stop_playing
exit
}
trap clean_up SIGHUP SIGINT SIGTERM
function recording(){
echo "Start Recording..."
arecord -D plughw:1,0 -d 9 -f S16_LE -c1 -r44100 -t wav /opt/baby_cry_rpi/recording/signal_9s.wav
}
function predict() {
echo "Predicting..."
echo -n "What is the prediction ?"
python /opt/baby_cry_rpi/script/make_prediction.py
PREDICTION=$(cat /opt/baby_cry_rpi/prediction/prediction.txt)
echo "Prediction is $PREDICTION"
}
function start_playing() {
if [[ $PLAYING == 0 ]]; then
echo "start playing"
aplay -D plughw:0,0 /opt/baby_cry_rpi/lullaby/lullaby_classic.wav
PLAYING=1
fi
}
function stop_playing(){
if [[ $PLAYING == 1 ]]; then
echo "stop playing"
PLAYING=0
fi
}
echo "Welcome to Parenting 2.0"
echo ""
while true; do
recording
predict
if [[ $PREDICTION == 0 ]]; then
stop_playing
else
CPT=$(expr $CPT + 1)
start_playing
fi
echo "State of the Process PREDICTION = $PREDICTION, PLAYING=$PLAYING, COMPTEUR=$CPT"
done
clean_up