Skip to content

Instantly share code, notes, and snippets.

@konradstrack
Created March 16, 2014 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konradstrack/9582541 to your computer and use it in GitHub Desktop.
Save konradstrack/9582541 to your computer and use it in GitHub Desktop.
A simple script for practicing for the TOEFL exam. It uses espeak to read questions from a file, and for each question records the response and plays it back.
#!/bin/bash
if [ $# -lt 2 ]; then
echo "usage: $1 questions_file output_dir"
exit -1
fi
questions_file=$1
output_dir=$2
prepare_time=15
speak_time=45
function countdown() {
start=$((`date +%s` + $1))
while [ "$start" -ge `date +%s` ]; do
left=$(($start - `date +%s`))
echo -ne "\r$2: `printf %2d $left`s"
sleep 1
done
}
function speak() {
espeak -ven+m3 -s150 "$1" 2&>/dev/null
}
while read line; do
number=`echo $line | cut -f1 -d"."`
question=`echo $line | cut -f2- -d"."`
# display and say the question
speak "Next question."
echo "Q: $question"
echo ""
speak "$question"
sleep 1
# wait until the preparation time is up
speak "You have $prepare_time seconds to prepare."
countdown $prepare_time "> time to prepare"
sleep 1
# start counting speaking time and record the speech
speak "Start speaking. You have $speak_time seconds."
echo ""
destination_file="$output_dir/${number}.wav"
arecord -f cd -q $destination_file &
arecord_pid=$!
countdown $speak_time "> time to speak"
kill $arecord_pid
speak "Time's up. Your speech will be played back."
aplay $destination_file
sleep 5
done < $questions_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment