-
Notifications
You must be signed in to change notification settings - Fork 0
/
blind-audio-test
executable file
·66 lines (49 loc) · 1.9 KB
/
blind-audio-test
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
#!/bin/bash
readonly TEST_COUNT=$1
readonly FILE1="$2"
readonly FILE2="$3"
readonly FILENAME1="${FILE1%.*}"
readonly FILENAME2="${FILE2%.*}"
# write FILE1 and FILE2 $TEST_COUNT times in play_order
for (( i = 1 ; i <= ${TEST_COUNT} ; i++ )); do
play_order="${play_order} ${FILE1} ${FILE2}"
done
# shuffle play_order
play_order=$(gshuf -e $play_order)
# split play_order at spaces into array
read -a play_order <<< $play_order
read_guess() {
read -p "guess $FILENAME1 or $FILENAME2: " guess
echo -en "\033[1A\033[2K"
}
(( correct_guesses_file1 = 0 ))
(( correct_guesses_file2 = 0 ))
# iterate element by element through play_order
for item in ${play_order[*]}; do
afplay -t 2 "$item"
read_guess
while [ "$guess" != "$FILENAME1" -a "$guess" != "$FILENAME2" ]; do
printf "invalid guess. guess again\n"
read_guess
done
if [ "$item" == "$FILE1" -a "$guess" == "$FILENAME1" ]; then
(( correct_guesses_file1+=1 ))
fi
if [ "$item" == "$FILE2" -a "$guess" == "$FILENAME2" ]; then
(( correct_guesses_file2+=1 ))
fi
done
(( wrong_guesses_file1 = TEST_COUNT-correct_guesses_file1 ))
(( wrong_guesses_file2 = TEST_COUNT-correct_guesses_file2 ))
printf "correct guesses for %s: %d\n" "$FILENAME1" $correct_guesses_file1
printf " wrong guesses for %s: %d\n" "$FILENAME1" $wrong_guesses_file1
printf "correct guesses for %s: %d\n" "$FILENAME2" $correct_guesses_file2
printf " wrong guesses for %s: %d\n" "$FILENAME2" $wrong_guesses_file2
printf "\n"
(( pct_correct_file1 = $correct_guesses_file1*100 / TEST_COUNT ))
(( pct_correct_file2 = $correct_guesses_file2*100 / TEST_COUNT ))
(( pct_correct_total = ($correct_guesses_file1 + $correct_guesses_file2) * 100 / (2*TEST_COUNT) ))
printf "%3d%% correct for %s\n" $pct_correct_file1 "$FILENAME1"
printf "%3d%% correct for %s\n" $pct_correct_file2 "$FILENAME2"
printf "%3d%% correct totally\n" $pct_correct_total
exit 0