#-- FILE: #-- practice'alg.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" sDefinitionsDir="/cygdrive/c/mjb/French/Definitions" iVolume=15 #cd /cygdrive/c/Mjb/French/Lesson1 echo 'starting script ... ' ls | grep '\.mp3$' > 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 ] ' iCount=0 while [ 1 -eq 1 ] do file=$(cat fileList.txt | gawk "BEGIN{srand();n=int(rand()*$iFileCount);} NR==n") word=$(echo $file | sed 's/\..*$//g') # echo "file=$file" # echo "word=$word" #./wav.exe $file /Q /V$iVolume gplay $file iCount=iCount+1 echo ">" read line #-- Loop for while the user enters commands while [ "$line" != "" ] do if [ "$line" = "a" ] then gplay $file fi 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 a .......plays the previous word Again. e .......looks up the text of the english equivalent of the french word which you just heard 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) 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 meanings from local files if [ "$line" = "e" ] then if [ -f $sDefinitionsDir/$word.tran.txt ] then cat $sDefinitionsDir/$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" = "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)