forked from shivasiddharth/Assistants-Pi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audio-test.sh
142 lines (141 loc) · 4.07 KB
/
audio-test.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
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
#!/bin/bash
YES_ANSWER=1
NO_ANSWER=2
QUIT_ANSWER=3
parse_user_input()
{
if [ "$1" = "0" ] && [ "$2" = "0" ] && [ "$3" = "0" ]; then
return
fi
while [ true ]; do
Options="["
if [ "$1" = "1" ]; then
Options="${Options}y"
if [ "$2" = "1" ] || [ "$3" = "1" ]; then
Options="$Options/"
fi
fi
if [ "$2" = "1" ]; then
Options="${Options}n"
if [ "$3" = "1" ]; then
Options="$Options/"
fi
fi
if [ "$3" = "1" ]; then
Options="${Options}quit"
fi
Options="$Options]"
read -p "$Options >> " USER_RESPONSE
USER_RESPONSE=$(echo $USER_RESPONSE | awk '{print tolower($0)}')
if [ "$USER_RESPONSE" = "y" ] && [ "$1" = "1" ]; then
return $YES_ANSWER
else
if [ "$USER_RESPONSE" = "n" ] && [ "$2" = "1" ]; then
return $NO_ANSWER
else
if [ "$USER_RESPONSE" = "quit" ] && [ "$3" = "1" ]; then
printf "\nGoodbye.\n\n"
exit
fi
fi
fi
printf "Please enter a valid response.\n"
done
}
select_option()
{
local _result=$1
local ARGS=("$@")
if [ "$#" -gt 0 ]; then
while [ true ]; do
local count=1
for option in "${ARGS[@]:1}"; do
echo "$count) $option"
((count+=1))
done
echo ""
local USER_RESPONSE
read -p "Please select an option [1-$(($#-1))] " USER_RESPONSE
case $USER_RESPONSE in
''|*[!0-9]*) echo "Please provide a valid number"
continue
;;
*) if [[ "$USER_RESPONSE" -gt 0 && $((USER_RESPONSE+1)) -le "$#" ]]; then
local SELECTION=${ARGS[($USER_RESPONSE)]}
echo "Selection: $SELECTION"
eval $_result=\$SELECTION
return
else
clear
echo "Please select a valid option"
fi
;;
esac
done
fi
}
echo ""
echo "First let's test the speaker output. Are you ready?"
parse_user_input 1 1 0
USER_RESPONSE=$?
if [ "$USER_RESPONSE" = "$YES_ANSWER" ]; then
echo ""
echo ""
echo "=============Testing Speaker output============="
speaker-test -t wav -l 2
fi
echo ""
echo ""
if [ "$USER_RESPONSE" = "$NO_ANSWER" ]; then
exit
fi
echo "Did you hear the audio from speaker?"
parse_user_input 1 1 0
USER_RESPONSE=$?
if [ "$USER_RESPONSE" = "$YES_ANSWER" ]; then
echo ""
echo ""
echo "Great!! Proceeding to test the microphones......"
echo ""
echo ""
echo "A 10 second audio sample will be recorded for testing. Are you ready?"
parse_user_input 1 1 0
USER_RESPONSE=$?
if [ "$USER_RESPONSE" = "$YES_ANSWER" ]; then
echo "Select your audio config that you used:"
select_option mic AIY-HAT-or-CUSTOM-HAT USB-DAC-or-USB-SOUNDCARD-or-USB-MIC
if [ $mic = AIY-HAT-or-CUSTOM-HAT ]; then
echo "=============Recording Mic Audio Sample============="
arecord -d 10 -D hw:0,0 -r 48000 -f S32_LE -c2 /home/pi/mic-test.wav
echo ""
elif [ $mic = USB-DAC-or-USB-SOUNDCARD-or-USB-MIC ];then
echo "=============Recording Mic Audio Sample============="
arecord -d 10 -D hw:1,0 -r 16000 -f S16_LE -c1 /home/pi/mic-test.wav
echo ""
fi
echo "Finished recording the samples."
echo ""
echo "Playing back the recorded audio sample......"
echo ""
aplay /home/pi/mic-test.wav
echo "Did you hear the recorded audio sample?"
parse_user_input 1 1 0
USER_RESPONSE=$?
if [ "$USER_RESPONSE" = "$YES_ANSWER" ]; then
echo ""
echo ""
echo "Great!! Proceed to installing the voice assistants...."
echo ""
echo ""
exit
fi
if [ "$USER_RESPONSE" = "$NO_ANSWER" ]; then
echo "Execute arecord -l in terminal and verify the card id with the ones mentioned in asound.conf file and .asoundrc file. Exiting..."
exit
fi
fi
fi
if [ "$USER_RESPONSE" = "$NO_ANSWER" ]; then
echo "Execute aplay -l in terminal and verify the card id with the ones mentioned in asound.conf file and .asoundrc file. Exiting..."
exit
fi