Monday, April 09, 2012

Talk to me Linux!

Just hacked together a simple proc to read text strings aloud using the espeak Linux command. Its good fun. It also shows how useful the gnocl::setOpts command  can be.

#---------------
# espeak.tcl
#---------------
## \file
# File documentation.
#\verbatim
#!/bin/sh
#\
exec tclsh "$0" "$@"
#\endverbatim

package require Gnocl

##
# -f <text file>
#       Text file to speak
# -a <integer>
#       Amplitude, 0 to 200, default is 100
# -g <integer>
#       Word gap. Pause between words, units of 10mS at the default speed
# -l <integer>
#       Line length. If not zero (which is the default), consider
#       lines less than this length as end-of-clause
# -p <integer>
#       Pitch adjustment, 0 to 99, default is 50
# -s <integer>
#       Speed in words per minute, 80 to 390, default is 170
# -v <voice name>
#       Use voice file of this name from espeak-data/voices
# -w <wave file name>
#       Write output to this WAV file, rather than speaking it directly
# -b   Input text encoding, 1=UTF8, 2=8 bit, 4=16 bit
# -m   Interpret SSML markup, and ignore other < > tags
# -q   Quiet, don't produce any speech (may be useful with -x)
# -x   Write phoneme mnemonics to stdout
# -X   Write phonemes mnemonics and translation trace to stdout
# -z   No final sentence pause at the end of the text
proc readAloud {args} {
    # set defaults and parse args
    gnocl::setOpts "-a 5 -s 110 $args"
    eval exec espeak -a $a -s $s [list $t]
}

readAloud -t "How now brown cow. She sell sea shells by the sea shore. Peter Piper picked a peck of pickled peppers."

Friday, April 06, 2012

Wednesday, March 28, 2012

gnocl::setOpts -new command

Sometimes I want to set a block of variables within procedure either as a set of defaults or as variables passed to a proc as options. Hitherto I've used a tcl proc to do this work but thought it high time to add this utility to the gnocl core. Ok, its not strictly graphics but it does make writing event handlers easier. Take the following for example:

doTagPopup -w %w -t %t -n %n -b %b -x %X -y %Y -matches OM|MANI|PADME|HUM|HRIH

The -w options can be used to create local variables. Here's a test snippet:


proc test-setOpts {args} { 
    gnocl::setOpts $args
    puts "$x $y $z"
 
    gnocl::setOpts [list j 4 k 5 l 6]
    puts "$j $k $l"
}

test-setOpts -x 1 -y 2 -z 3

In the first call the args string is parsed and values set en bloc. The leading '-' will be stripped away. In the second example, a paired list is given from which values will be set.


Tuesday, March 27, 2012

Getting text tag ranges

Completed code for returning a list of the ranges of a text tag within a gnocl::text widget.

widgetId tag ranges tagName


Implmenting text tag popup menus

Here's a short script to show how to get popup menus appearing for text tag objects.

#---------------
# texttag-popup.tcl
#---------------
#!/bin/sh
#\
exec tclsh "$0" "$@"

package require Gnocl

set txt [gnocl::text -wrapMode word]

gnocl::window -child $txt -setSize 0.25

#---------------
# display popup menu
#---------------
proc doTagPopup {args} {
   
    foreach {arg val} $args { set [string trimleft $arg "-"] $val }

    if {$t == "buttonPress" && $b == "3" } {
       
        # these may need runtime re-definition
        proc doHello {} {puts hello}
        proc doGoodBye {} {puts goodbye}
       
        set menu [gnocl::menu -title "menu" -tearoff 0]
        $menu add [gnocl::menuItem -text "Hello" -onClicked doHello]
        $menu add [gnocl::menuItem -text "Goodbye" -onClicked doGoodBye]
        $menu popup $x $y
       
        #proc doHello {} {}
        #proc doGoodBye {} {}       
    }
   
}


$txt tag create tag_popup -onEvent {doTagPopup -t %t -b %b -x %X -y %Y } -underline single  -foreground blue

$txt lorem

$txt tag apply {1 0} "1 20" -tags tag_popup

Sunday, March 11, 2012

Another simple error fixed -gnocl::dialog

The gnocl::dialog command has been throwing out a 'message-type' warning. The cause of this has now been removed.


Thursday, February 09, 2012

json_shell_utils.tcl