#!/usr/local/bin/wish -f global tk_library global tk_version # how wide is the underlying conceptual surface? global width # how tall is the underlying conceptual surface for the align window? global alignht # how tall is the underlying conceptual surface for the error window? global errht #how wide is the actual display -- small for laptop, bigger for big machines global dispwd #how tall is the actual align window? global aldispht #how tall is the actual error window? global errdispht set dispwd 1000 set aldispht 50 #set errdispht 220 set errdispht 400 # width,alignht,errht are passed in as parameters global errwin_cv_font set errwin_cv_font "lucidasanstypewriter-bold-12" global errwin_cv_small_font set errwin_cv_small_font "lucidasanstypewriter-bold-10" global errwin_cv_medium_font set errwin_cv_medium_font "lucidasanstypewriter-12" # # For procs tk_errwin_{line,rect,text}, win should be "err" # proc tk_errwin_line {win x1 y1 x2 y2} { .errwin.$win.cv create line $x1 $y1 $x2 $y2 } proc tk_errwin_rect {win x1 y1 x2 y2} { .errwin.$win.cv create rectangle $x1 $y1 $x2 $y2 } proc tk_errwin_text {win x y txt color} { global errwin_cv_font .errwin.$win.cv create text $x $y -text "$txt" \ -anchor nw \ -fill $color \ -font $errwin_cv_font } proc tk_errwin_blue_text {win x y txt} { global errwin_cv_font .errwin.$win.cv create text $x $y -text "$txt" \ -anchor nw \ -fill blue \ -font $errwin_cv_font } proc tk_errwin_black_text {win x y txt} { global errwin_cv_font .errwin.$win.cv create text $x $y -text "$txt" \ -anchor nw \ -fill black \ -font $errwin_cv_font } proc tk_errwin_green_text {win x y txt} { global errwin_cv_font .errwin.$win.cv create text $x $y -text "$txt" \ -anchor nw \ -fill green \ -font $errwin_cv_font } proc tk_errwin_small_text {win x y txt color} { global errwin_cv_small_font .errwin.$win.cv create text $x $y -text "$txt" \ -anchor nw \ -fill $color\ -font $errwin_cv_small_font } proc tk_errwin_medium_text {win x y txt color} { global errwin_cv_medium_font .errwin.$win.cv create text $x $y -text "$txt" \ -anchor nw \ -fill $color\ -font $errwin_cv_medium_font } proc tk_errwin_xview {pos} { .errwin.align.cv xview $pos .errwin.err.cv xview $pos } # .errwin display window: # wd = window width (pixels) # aht = height of align window # eht = height of err window # ppf = pixels/frame (10) proc tk_errwin_create {wd aht eht} { global width global alignht global errht global dispwd global aldispht global errdispht if { [winfo exists .errwin]} { destroy .errwin } toplevel .errwin -width [expr 50 + $wd] -height [expr $eht + $aht + 100] set width $wd set alignht $aht set errht $eht # align subwindow -- horizontal scroll only, its own scroll bar frame .errwin.align canvas .errwin.align.cv -width $dispwd -height $aldispht \ -scrollregion "0 0 $width $alignht" -background white \ -xscrollcommand ".errwin.align.hsb set" scrollbar .errwin.align.hsb -command ".errwin.align.cv xview" -orient horizontal \ -border 2 -relief raised -width 10 pack .errwin.align.hsb -side bottom -fill x pack .errwin.align.cv -side left -fill both # err subwindow -- horizontal and vertical scroll frame .errwin.err canvas .errwin.err.cv -width $dispwd -height $errdispht \ -scrollregion "0 0 $width $errht" -background white \ -xscrollcommand ".errwin.err.hsb set" -yscrollcommand ".errwin.err.vsb set" scrollbar .errwin.err.hsb -command ".errwin.err.cv xview" -orient horizontal \ -border 2 -relief raised -width 10 pack .errwin.err.hsb -side bottom -fill x scrollbar .errwin.err.vsb -command ".errwin.err.cv yview" -orient vertical \ -border 2 -relief raised -width 10 pack .errwin.err.vsb -side right -fill y pack .errwin.err.cv -side left -fill both # button .errwin.close -border 2 -width 10 -text "bisou" -command "destroy .errwin" # pack .errwin.close -side top -pady 5 pack .errwin.align -side top -pady 1 -fill x -expand yes pack .errwin.err -side top -pady 1 -fill x -fill y -expand yes wm geometry .errwin +1+10 update } # # options # #option add *Background Gray80 #option add *Button.Background Gray90 #option add *Message.Background Gray90 #option add *Listbox.Background Gray90 #option add *Text.Background CornSilk #option add *Entry.Background CornSilk #option add *activeForeground black #option add *selectBackground gray45 #option add *selectForeground white #option add *Button.Height 2 global textfont global ht global wd proc tk_msg {msg} { .bot.msg configure -text $msg update } proc tk_utt {} { if { [winfo exists .errwin]} { destroy .errwin } ui_utt [.mfcfr.file get] } set textfont "lucidasanstypewriter-18" #bind buttons frame .bot #button .bot.ok -text "ANALYZE" -border 2 -width 10 -command "tk_era" #bind .bot.ok {tk_analyze_uttid} button .bot.quit -text "QUIT" -border 2 -width 10 -command "destroy ." bind .bot.quit {destroy .} #message .bot.msg -font lucidasanstypewriter-bold-24 -justify left -aspect 100000 -anchor w #pack .bot.ok -side left -padx 5 -pady 1 #pack .bot.msg -side left -padx 5 -pady 1 -fill x -expand yes pack .bot.quit -side left -padx 5 -pady 1 pack .bot -side top -fill x -expand yes proc tk_errwin_print_align {utt ref hyp} { tk_errwin_blue_text align 0 0 "Utterance $utt" tk_errwin_blue_text align 0 20 "REF: " tk_errwin_medium_text align 30 20 $ref black tk_errwin_blue_text align 0 30 "HYP: " tk_errwin_medium_text align 30 30 $hyp black } #variables that control vertical and horizontal spacing in the err window global region_space set region_space 300 global top_space set top_space 60 global pathht set pathht 40 global begin_x set begin_x 40 global box_ht set box_ht 20 global lab_x set lab_x 2 global ref_vspace set ref_vspace 45 global hyp_vspace set hyp_vspace 25 global ppf set ppf 5 # start and end frame of error region being printed global start_frame global end_frame # various placement variables shared by proc's below global ref_box_y global hyp_box_y global ref_lab_y global hyp_lab_y # CAREFUL! This routine depends on global variables set in tk_errwin_print_err # for vertical spacing parameters. It should be called after the appropriate # call to that routine. proc tk_errwin_print_ref_word {sf ef word lmsrc lmscore normac} { global ppf global box_ht global ref_box_y global ref_lab_y global begin_x global start_frame global sf_diff set sf_diff [expr $sf - $start_frame] global word_sf set word_sf [expr $begin_x + $sf_diff*$ppf] global ef_diff set ef_diff [expr $ef - $start_frame] global word_ef set word_ef [expr $begin_x + $ef_diff*$ppf] set word_ln [expr $word_ef - $word_sf] tk_errwin_rect err $word_sf $ref_box_y $word_ef [expr $ref_box_y + $box_ht] tk_errwin_black_text err [expr $word_sf + 2] $ref_lab_y "$word" # place the word's LM source set lmsrc_y [expr $ref_box_y - 20] tk_errwin_small_text err [expr $word_sf + 2] $lmsrc_y "$lmsrc" orange # place the word's LM score if [expr $word_ln > 30] then {set lmscore_y [expr $ref_box_y - 10]} else {set lmscore_y [expr $ref_box_y - 30]} tk_errwin_small_text err [expr $word_sf + 2] $lmscore_y "$lmscore" orange # place the word's normalize acoustic score set normac_x [expr (($word_ef - $word_sf) / 2) + $word_sf - 30] set normac_y [expr $ref_box_y + $box_ht + 2] tk_errwin_small_text err $normac_x $normac_y "$normac" red } # CAREFUL! This routine depends on global variables set in tk_errwin_print_err # for vertical spacing parameters. It should be called after the appropriate # call to that routine. proc tk_errwin_print_hyp_word {sf ef word lmsrc lmscore normac} { global ppf global box_ht global hyp_box_y global hyp_lab_y global begin_x global start_frame set sf_diff [expr $sf - $start_frame] set word_sf [expr $begin_x + $sf_diff*$ppf] set ef_diff [expr $ef - $start_frame] set word_ef [expr $begin_x + $ef_diff*$ppf] set word_ln [expr $word_ef - $word_sf] # draw the word's box and put the word label in it tk_errwin_rect err $word_sf $hyp_box_y $word_ef [expr $hyp_box_y + $box_ht] tk_errwin_black_text err [expr $word_sf + 2] $hyp_lab_y "$word" # place the word's LM source set lmsrc_y [expr $hyp_box_y + $box_ht+ 10] tk_errwin_small_text err [expr $word_sf + 2] $lmsrc_y "$lmsrc" orange # place the word's LM score if [expr $word_ln > 30] then {set lmscore_y [expr $hyp_box_y + $box_ht]} else {set lmscore_y [expr $hyp_box_y + $box_ht + 20]} tk_errwin_small_text err [expr $word_sf + 2] $lmscore_y "$lmscore" orange # place the word's normalize acoustic score set normac_x [expr (($word_ef - $word_sf) / 2) + $word_sf - 30] set normac_y [expr $hyp_box_y - 12] tk_errwin_small_text err $normac_x $normac_y "$normac" red } proc tk_errwin_print_err {sf ef lmref lmtot acref actot totref tot regno} { global ppf global top_space global pathht global begin_x global box_ht global lab_x global ref_vspace global hyp_vspace global start_frame global end_frame global ref_box_y global hyp_box_y global ref_lab_y global hyp_lab_y global region_space # beginning of loop for each error region # baseline y-spacing set current_err_y [expr ($regno - 1) * $region_space] # error region label tk_errwin_blue_text err 0 $current_err_y "Error region:" # line on which totals labels appear set totals_y [expr $current_err_y + 10] # upper reference line set base_y [expr $current_err_y + 20] # halfway down visually in error region set half_y [expr $current_err_y + $top_space + $pathht] # lower reference line set bottom_y [expr $half_y + $pathht] # line on which timeline appears set timeline_y [expr $bottom_y + 50] # value in frames of start frame set start_frame $sf # value in frames of end frame set end_frame $ef # number of frames in error region set num_frames [expr $end_frame - $start_frame] # x position of end frame set end_x [expr $begin_x + $num_frames*$ppf] # horizontal spacing of final tallies set totals_wd 70 # x position of LM tally set LM_lab_x [expr $end_x + $totals_wd] # x position of AC tally set AC_lab_x [expr $LM_lab_x + $totals_wd] # x position of total tally set TOT_lab_x [expr $AC_lab_x + $totals_wd] # write tally labels tk_errwin_blue_text err $LM_lab_x $totals_y "LM" tk_errwin_blue_text err $AC_lab_x $totals_y "AC" tk_errwin_blue_text err $TOT_lab_x $totals_y "TOT" # write the timeline and frame labels tk_errwin_line err $begin_x $timeline_y $end_x $timeline_y tk_errwin_text err $begin_x [expr $timeline_y + 2] "$start_frame" RosyBrown tk_errwin_text err $end_x [expr $timeline_y + 2] "$end_frame" RosyBrown # vertical position of top of reference boxes set ref_box_y [expr $half_y - $ref_vspace] # vertical position of top of reference label and words set ref_lab_y [expr $ref_box_y + 5] # write ref label tk_errwin_blue_text err $lab_x $ref_lab_y "REF: " # vertical position of top of hypothesis boxes set hyp_box_y [expr $half_y + $hyp_vspace] # vertical position of top of hypothesis label and words set hyp_lab_y [expr $hyp_box_y + 5] # write hyp label tk_errwin_blue_text err $lab_x $hyp_lab_y "HYP: " # write LM tally in correct location if $lmref then {set lmtot_y $ref_lab_y} else {set lmtot_y $hyp_lab_y} tk_errwin_text err $LM_lab_x $lmtot_y "$lmtot" orange # write AC tally in correct location if $acref then {set actot_y $ref_lab_y} else {set actot_y $hyp_lab_y} tk_errwin_text err $AC_lab_x $actot_y "$actot" red # write total tally in correct location if $totref then {set tot_y $ref_lab_y} else {set tot_y $hyp_lab_y} tk_errwin_text err $TOT_lab_x $tot_y "$tot" black #hacked in example } # create the error region tk_errwin_create 4000 100 2500 # print out the align information #tk_errwin_print_align "4q3c0209" ". . . when markets CONVULSED **** because of . . ." ". . . when markets CAN(2) POST because of . . ." # print the overall error region information #tk_errwin_print_err 780 843 1 1049564 1 260407 1 1309971 1 # print each word in the REF portion of the region #tk_errwin_print_ref_word 780 843 "CONVULSED" "UNK" -475593 -161077 # print each word in the HYP portion of the region #tk_errwin_print_hyp_word 780 798 "CAN(2)" "BB_B" -638717 -176188 #tk_errwin_print_hyp_word 798 843 "POST" "BB_B" -886440 -161402 # repeat for good practice #tk_errwin_print_err 780 843 1 1049564 1 260407 1 1309971 2 #tk_errwin_print_ref_word 780 843 "CONVULSED" "UNK" -475593 -161077 #tk_errwin_print_hyp_word 780 798 "CAN(2)" "BB_B" -638717 -176188 #tk_errwin_print_hyp_word 798 843 "POST" "BB_B" -886440 -161402 #focus . #tkwait window .