#!/bin/bash #set -x ################################################################### # A bash script meant to be used from a drag and drop # # icon in kde to send various txt/html files and urls # # to ViaVoice. It is possible to pause/restart the voice output. # # Simultaneously sends the text to the kless pager as it is read. # # Special handling for mhonarc mail links. (DnD emails from kfm) # ################################################################### # # Requires ViaVoice with cmdlinespeakfile in /usr/local/lib # Requires gdialog in /usr/bin # Requires lynx in /usr/bin # Requires html2pdbtxt in /usr/local/bin # Requires dehtml in /usr/local/bin # Put this script in your path and make it executable # Make an Icon in kde called Reader.kdelnk (or whatever you like) # In "Execute" tab put 'readfile %f' (without the quotes) # Now you can drag and drop to it. Or, just click and type or paste text. # Also works nicely on a button in emelfm as 'readfile %f' # ########### # History # ########### # # Fri_Aug_04_2000_19:13:11_PDT initial write v.0 # Tue Aug 08 08:29:45 PDT 2000 added guimaker support # clean ups v0.1 # Tue Aug 08 09:25:27 PDT 2000 changed to gdialog v0.2 # Tue Aug 08 19:45:40 PDT 2000 reads txt strngs from dialog # not just http v0.3 # Tue Aug 08 23:38:17 PDT 2000 trying html2pdbtxt # added file & ftp types v0.4 # Wed Aug 09 10:22:21 PDT 2000 put html2pdbtxt everywhere # hopefully fixed dn'drop bug v0.4b # Wed Aug 09 13:09:15 PDT 2000 rewrote the script to use functions # added more comments & cleaned up # added filters for '==' '##' v0.5 # Wed Aug 09 18:41:47 PDT 2000 got rid of the need for a console # Thu Aug 10 11:35:20 PDT 2000 added a pause feature v0.6 # Thu Aug 10 14:45:04 PDT 2000 added paths to cmds and titles to gui # started on wait pid of spk or gui # changed to cmdlinespeakfile v0.7 # Fri Aug 11 17:47:18 PDT 2000 # readfile_version='0.7' ########### # ToDo # ########### # # Find way to use gdialog to killall, so don't need xterm from icon-done # Find a way to add a "pause" feature for the speech.can ctrlZ in shell etc.-done # Put this mess into bash functions - done # Should change the way mhonarc files are recognized to remove msg limit # Plain text gets wrapped funny sometimes - like viewing scripts (fr htmlpdbtxt) # add --title to gdialog etc.-done # chng to cmdlinespeakfile? -yes, done # add paths to things for speed -done # have it exit without clicking cancel when finished - hmmm... # move the s/frm0/msg0/ up higher in case paste from netscape # get rid of cat to reduce processes # repeat button? # store speech as wav simultaneously? # send text to a file? # record a real speech note somewhere? # if [ "$1" = "-version" ]; then echo 'readfile version' $readfile_version exit fi echo 'readfile version' $readfile_version #ViaVoice number to use voice="\`v2 " #voice="" mainjob=$$ function geturl { lynx -source -nolist -image_links -hiddenlinks=ignore -underscore $url >~/reader.html html2pdbtxt ~/reader.html ~/reader.txt # w3m -dump -S -F -no-graph -cols 80 ~/reader.html > ~/reader.txt # cat ~/reader.txt | fold -s | gless & gless < ~/reader.txt & pgrjob=$! sayfile=$(cat ~/reader.txt) # sayfile <~/reader.txt) sayfile=${sayfile//"__"/""} # patts to squeeze out sayfile=${sayfile//"\#\#"/""} sayfile=${sayfile//"=="/""} sayfile=$voice" "$sayfile echo ${sayfile} > ~/readersay.txt return } function speakfile { cmdlinespeakfile ~/readersay.txt & spkjob=$! stopnow=1 until [ "$stopnow" = "" ]; do stopnow=$(gdialog --title "Readfile" --menu "Commands" 50 50 50 "19" "Pause " "18" "Continue" 2>&1);export stopnow & askjob=$! wait $askjob if [ "$(ps h p $spkjob)" = "" ]; then break; fi if [ "$stopnow" != "$lasttime" ];then killall -$stopnow "cmdlinespeakfile" fi lasttime=$stopnow #don't send the same signal twice - it hates that! done kill -9 $spkjob kill -9 $pgrjob ##/usr/bin/killall kioslave exit } # if no arg is passed let's try to get a url with gdialog if [ "$1" = "" ]; then url=$(gdialog --title "Readfile" --inputbox "Feed me! Reader Hungry Now!" 50 50 2>&1) if [ "$url" = "" ]; then # still nothing to say exit fi if [ ${url%%:*} = "http" ];then geturl elif [ ${url%%:*} = "file" ];then geturl elif [ ${url%%:*} = "ftp" ];then geturl else sayfile=$url # not a url after all - just pasted text echo $voice ${sayfile} > ~/readersay.txt fi speakfile fi # mhonarc names the source for frames *not* the file we want # when the "message" is dragged and dropped on us. # fortunately it's the same number file with a diff. prefix # the files we want start with msg instead of frm # put the '0' in in case frm is legit in the file name # limits the # of messages in mailbox to < 9999 # substitute the literal string 'frm0' with 'msg0' url=${1//frm0/msg0} # if it's not a msg0 file from mhonarc just say the thing and exit.. # filters html out if [ "$1" = "$url" ]; then # nothing changed, wasn't a mhonarc file geturl speakfile fi #################################### # parse mhonarc msg0nnnn.html file # #################################### # The next part of this script just deals with mhonarc html mail files # count the lines in the file lines=$(cat $url | wc -l) # grep the lines that mark the begin/end of the msg body beginmsg=$(cat -n $url | grep -i "") endmsg=$(cat -n $url | grep -i "") # get the number we want from the begin of the line beginmsg=$(echo ${beginmsg%%<*}) endmsg=$(echo ${endmsg%%<*}) # compute tail and head numbers from them tailstart=$(echo "$lines-$beginmsg-1"|bc -l) headstart=$(echo "$lines-($lines-$endmsg)-$beginmsg"|bc -l) sayfile=$(cat $url | tail -n$tailstart | head -n$headstart | dehtml) echo ${sayfile} > ~/readersay.txt speakfile