Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/bash
- PLAYER="play -q"
- # `play` is from sox package; `man soxformat` for supported formats
- if [[ $# <3 ]]; then
- echo 'ABX test for audio files.'
- echo
- echo "Usage: $0 <n> <wave_A> <wave_B>"
- echo ' n - number of tests performed (n >= 10 is recommended)'
- echo ' wave_{A,B} - audio files supported by PLAYER'
- echo ' Make your waves shorter.'
- echo
- echo 'Correct results required for a 95% confidence level:'
- echo 'n 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25'
- echo 'CR 9 9 10 10 11 12 12 13 13 14 15 15 16 16 17 18'
- echo 'In general, CR must be greater than n/2+sqrt(n).'
- echo
- echo "PLAYER = \"${PLAYER}\""
- echo
- exit 1
- fi
- n=$1
- wave_A="$2"
- wave_B="$3"
- waves_AB=("$wave_A" "$wave_B")
- AB=("A" "B")
- echo "In each test, \"${wave_A}\" then \"${wave_B}\" will be played."
- echo "Then you'll hear randomly selected one — \"X\"."
- echo "After the third sample you'll be asked for what file been played."
- echo 'Answer only "A" or "B" and then press Enter.'
- correct_answers=0
- for i in $(seq $n); do
- echo
- echo "Test #${i} of ${n}:"
- echo -ne "\tA | Press Enter when ready. "; read
- $PLAYER "$wave_A"
- echo -ne "\tB | Press Enter when ready. "; read
- $PLAYER "$wave_B"
- random=$(( $RANDOM % 2 ))
- wave_X=${waves_AB[random]}
- X=${AB[random]}
- echo -ne "\tX | Press Enter when ready. "; read
- $PLAYER "$wave_X"
- while true; do
- echo -ne '\tWas that A or B? : '
- read answer
- if [[ $answer =~ ^[aAbB] ]]; then
- break
- fi
- done
- if [[ ($answer =~ ^[aA] && $X == 'A') || \
- ($answer =~ ^[bB] && $X == 'B') ]]; then
- correct_answers=$(( $correct_answers + 1 ))
- fi
- done
- echo
- echo "Congratulations! You've done all the ${n} tests!"
- echo "Your result is ${correct_answers}/${n}."
- echo "Bye."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement