#-- FILE: #-- vocab.sh #-- DESCRIPTION: #-- This script allows the user to practice his/her #-- aural comprehension of Spanish. It plays the sound #-- files of spanish words and phrases. #-- The script loops infinitely (until the user quits) #-- playing a random sound file from a directory. #-- #-- The script assumes that the sound files are named #-- in accordance with the spanish word or phrase which #-- is spoken within them. #-- #-- In other words, if the sound file contains the #-- spoken spanish word 'bocadillo' then the file will #-- be named 'bocadillo.wav' #-- AUTHOR: #-- mj bishop #-- LOCATION: #-- http://www.geocities.com/matth3wbishop/eg/unix-shell/ #-- DATES: may 02 #-- urls of online spanish dictionaries. sUrlHarperCollins="http://www.wordreference.com/es/en/translation.asp?spen" sUrlSpanishDict="http://www.spanishdict.com/AS.cfm?e" iVolume=15 echo 'starting script ... ' ls * | grep '\.wav$' > fileList.txt iFileCount=$(cat fileList.txt | wc -l | sed 's/^ *//g') # echo "fc="$iFileCount echo ' WELCOME TO THE SPANISH AURAL PRACTICE SCRIPT ============================================ please press... h or ? to see a help message listing commands q to quit the script to play the next spanish word (sound file) [ press the letter then press ] ' while [ 1 -eq 1 ] do file=$(cat fileList.txt \ | awk "BEGIN{srand();n=int(rand()*$iFileCount);} NR==n" \ | sed 's/words\///g') word=$(echo $file | sed 's/\..*$//g' | sed 's/words\///g') # echo "file=$file" # echo "word=$word" ./wav.exe $file /Q /V$iVolume echo '>' read line #-- Loop for while the user enters commands while [ "$line" != "" ] do if [ "$line" = "a" ] then ./wav.exe $file /Q /V$iVolume fi if [ "$line" = "q" ] then echo 'Good-Bye' exit 0 fi if [ "$line" = "h" -o "$line" = "?" ] then echo ' SOME HELP INFORMATION This Spanish Practice script accepts the following commands: q .......ends the script e .......looks up the text of the english equivalent of the spanish word which you just heard (requires an internet connection) s .......displays the text of the spanish word which you just heard r .......allows the user to rename the sound file of the word which was just played. This is useful when the name of the file does not correspond to the word(s) spoken in it. l .......allows the user to lookup the english translation (equivalent or reversal) of any given spanish word. (requires an internet connection) d .......looks up a dictionary file for a translation v .......changes the volume which the sound files are spoken at (eg v20 sets volume to 20) ? or h ..display this help message .plays the next spanish word (sound file) ' fi #-- volume control if [ $(echo "$line" | tr -d '[0-9 ]') = "v" ] then echo "Volume was $iVolume" iVolume=$(echo $line | tr -d 'v' | tr -d ' ') echo "Volume now $iVolume" fi #-- lookup local dictionary if [ "$line" = "d" ] then cat dict.txt | grep -A4 $word | sed '1d' fi #-- lookup english translation on internet. if [ "$line" = "e" ] then #-- wget -o temp.txt -O - -nd http://www.spanishdict.com/AS.cfm?e=$word | grep -A1 'ED.cfm' | sed -e '/ED\.cfm/d' -e 's/<\/a>//g' if [ -f ../Definitions/$word.tran.txt ] then cat ../Definitions/$word.tran.txt | head -24 else echo " The translation of the word $word was not found locally Use the 'l' command to look up the word on the Internet. " fi fi if [ "$line" = "s" ] then echo "Spanish: $word" fi if [ "$line" = "r" ] then echo "Rename the file $file to what? (c=cancel)" read sNewFileName if [ "$sNewFileName" != "c" ] then mv $file $sNewFileName echo "File $file renamed to $sNewFileName" else echo "File $file not renamed" fi fi if [ "$line" = "l" ] then echo 'Enter an spanish word to translate + ' echo '(c=cancel) ' read sLookupWord if [ "$sLookupWord" != "c" ] then echo '(looking up www.wordreference.com/es/en/ ...):' #-- spanishdict.com hasn't as many words as wordreference.com #-- wget -o temp.txt -O - -nd $sUrlSpanishDict=$sLookupWord | grep -A1 'ED.cfm' | sed -e '/ED\.cfm/d' -e 's/<\/a>//g' lynx --dump $sUrlHarperCollins=$sLookupWord \ | sed -n '/\[3\]/,/\[4\]/p' \ | sed '1d' | head -24 fi #-- if c pressed fi #-- if $line=l echo '>' read line done #-- user command loop echo '-----------' done #-- infinite loop (until user presses q)