#-- FILE: #-- vocab-f.sh #-- DESCRIPTION: #-- This script allows the user to practice his/her #-- aural comprehension of French. It plays the sound #-- files of french 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 french word or phrase which #-- is spoken within them. #-- #-- In other words, if the sound file contains the #-- spoken french word 'rouge' then the file will #-- be named 'rouge.wav' #-- AUTHOR: #-- mj bishop #-- DATES: may 02 #-- urls of online french dictionaries. sUrlHarperCollins="http://www.wordreference.com/fr/en/translation.asp?fren" 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 FRENCH AURAL PRACTICE SCRIPT ============================================ please press... h or ? to see a help message listing commands q to quit the script to play the next french 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") word=$(echo $file | sed 's/\..*$//g') # echo "file=$file" # echo "word=$word" wav $file /Q /V$iVolume echo '>' read line #-- Loop for while the user enters commands while [ "$line" != "" ] do if [ "$line" = "q" ] then echo 'Good-Bye' exit 0 fi if [ "$line" = "h" -o "$line" = "?" ] then echo ' SOME HELP INFORMATION This French Practice script accepts the following commands: q .......ends the script e .......looks up the text of the english equivalent of the french word which you just heard (requires an internet connection) t .......displays the text of the french 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 french 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 french 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 echo '(looking up www.wordreference.com/fr/en/ ...):' #-- The line below looks up the word #-- on a dictionary site and returns the #-- English equivalents by extracting the answer from #-- the html of the returned web-page. #-- This assumes that the file name of the sound file #-- (without the extension) is the written french version #-- of the word being said. lynx --dump $sUrlHarperCollins=$word \ | sed '/ *\[[0-9]*\]/d' \ | sed -n '/ *See Also/,/ *-The Collins/p' \ | sed -e '1d' -e '$d' \ | head -23 echo "French: $word" fi if [ "$line" = "t" ] then echo "French: $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 a french word to translate + ' echo '(c=cancel) ' read sLookupWord if [ "$sLookupWord" != "c" ] then echo '(looking up www.wordreference.com/fr/en/ ...):' lynx --dump $sUrlHarperCollins=$sLookupWord > tmp1.html sed '/ *\[[0-9]*\]/d' tmp1.html | \ sed -n '/ *See Also/,/ *-The Collins/p' | \ sed -e '1d' -e '$d' | head -23 rm tmp1.html fi #-- if c pressed fi #-- if $line=l echo '>' read line done #-- user command loop echo '-----------' done #-- infinite loop (until user presses q)