4 # Intializing Praat script
6 # SpeakGoodChinese: InitializeSGC2.praat defines and sets the global variables
7 # and loads general SGC2 code
9 # Copyright (C) 2007-2010 R.J.J.H. van Son and 2010 the Netherlands Cancer Institute
10 # The SpeakGoodChinese team are:
11 # Guangqin Chen, Zhonyan Chen, Stefan de Koning, Eveline van Hagen,
12 # Rob van Son, Dennis Vierkant, David Weenink
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
29 # Do not store these variables as preferences
30 sgc.nonPreferences$ = " config.savePerf config.openPerf config.clearSummary config.audioName "
32 # Information for logging activity
33 currentDate$ = date$()
34 dateYear$ = right$(currentDate$, length(currentDate$) - rindex(currentDate$, " "))
35 logtimeStamp$ = replace_regex$(currentDate$, "[^a-zA-Z0-9\-_]", "-", 0)
36 currentLogDirectory$ = ""
37 feedbackTablePrefix$ = "Feedback"
38 feedbackTableName$ = ""
39 evaluationTablePrefix$ = "Evaluation"
40 evaluationTableName$ = ""
41 performanceTableName$ = "Performance"
46 yFeedback = yWordlist + 5
47 yPinyin = yFeedback + 10
48 yContour = yPinyin + 15
49 wipeContourArea$ = "demo Paint rectangle... White 20 80 'yContour' 100"
50 wipePinyinArea$ = "demo Paint rectangle... White 20 80 'yPinyin' 'yContour'"
51 wipeFeedbackArea$ = "demo Paint rectangle... White 0 100 'yFeedback' 'yPinyin'"
52 wipeWordlistArea$ = "demo Paint rectangle... White 20 80 'yWordlist' 'yFeedback'"
54 # Pop-Up window colors
55 sgc2.popUp_bordercolor$ = "{0.5,0.5,1}"
56 sgc2.popUp_backgroundcolor$ = "{0.9,0.9,1}"
58 # Initialize parameters
61 sgc.currentWordlist = -1
63 sgc.currentWordNum = 1
64 sgc.numberOfDisplayedWords = 0
68 sgc.customLanguage$ = ""
77 sgc.failedAttempts = 0
79 config.deleteWordlist = -1
80 config.displayNumbers = 1
81 config.displayPinyin = 1
82 config.displayChar = 0
83 config.displayTrans = 1
84 config.useSoundExample = 1
85 config.synthesis$ = "_DISABLED_"
86 config.input$ = "Microphone"
87 config.showBackground = 1
88 sgc2.noiseThresshold = -30
93 config.voicesTTS$ = "default f1 f2 f3 f4 f5 m1 m2 m3 m4 m5 m6 m7"
95 sgc.nativeOSXTTScommand$ = "say -vTing-Ting --rate=95"
96 sgc.nativeLinuxTTScommand$ = "spd-say -l zh -t female1 -r -60"
97 #sgc.nativeWindowsTTScommand$ = "mshta.exe vbscript:Execute(""CreateObject(""""SAPI.SpVoice"""").Speak """"<voice gender='female' xml:lang='zh-CN'><rate speed='-5'>$$$</rate></voice>"""":Close"")"
98 sgc.nativeWindowsTTScommand$ = "mshta.exe vbscript:Execute(""CreateObject(""""SAPI.SpVoice"""").Speak """"<voice gender='female' xml:lang='zh-CN'><rate speed='-5'><pron sym='@@@'/></rate></voice>"""":Close"")"
99 sgc.nativeTTScommand$ = ""
102 config.clearSummary = 0
103 config.audioName$ = ""
106 mainPage.saveAudio$ = ""
107 sgc.allWordLists = -1
109 sgc_ToneProt.minimumPitch = 40
110 sgc_ToneProt.maximumPitch = 600
112 # Platform dependent settings
113 if macintosh or windows
114 config.displayChar = 1
115 config.displayNumbers = 0
117 if windows and endsWith(build_SHA$, " XP")
118 config.displayChar = 0
119 config.displayNumbers = 0
122 config.displayChar = 0
123 config.displayNumbers = 1
127 samplingFrequency = 44100
129 samplingFrequency = 44100
131 samplingFrequency = 44100
135 # Be careful: Logging and Replaying can have side-effects
136 # sgc2.logging$ = "call saveLogOfActivity"
138 # When this is not "# ", the command 'replaySGC2Log$' will be run!
139 if not variableExists("replaySGC2Log$")
140 replaySGC2Log$ = "# "
143 config.language$ = "EN"
144 config.register = 249
145 preferencesAppFile$ = preferencesAppDir$+"/sgc2rc.txt"
146 preferencesLogDir$ = "'preferencesAppDir$'/log"
147 preferencesTableDir$ = "'preferencesAppDir$'/GUI"
148 sgc2wordlists$ = "'preferencesAppDir$'/wordlists"
149 localWordlistDir$ = sgc2wordlists$
151 # Global word lists must be installed BY THE ADMINISTRATOR
152 # This means, create the directory 'globalwordlists$' and
153 # fill it with wordlist directories containing wordlist.Table
154 # and audio files. They can be copied from a local directory.
155 globalwordlists$ = ""
156 globaltablelists$ = ""
159 globalwordlists$ = "/etc/'sgc2.demoAppName$'/wordlists"
160 globaltablelists$ = "/etc/'sgc2.demoAppName$'/GUI"
161 globalTTSdir$ = "/etc/'sgc2.demoAppName$'/TTS"
163 globalwordlists$ = "/Library/Preferences/'sgc2.demoAppName$'/wordlists"
164 globaltablelists$ = "/Library/Preferences/'sgc2.demoAppName$'/GUI"
165 globalTTSdir$ = "/Library/Preferences/'sgc2.demoAppName$'/TTS"
167 globalwordlists$ = "C:/Documents and Settings/All Users/Application Data/'sgc2.demoAppName$'/wordlists"
168 globaltablelists$ = "C:/Documents and Settings/All Users/Application Data/'sgc2.demoAppName$'/GUI"
169 globalTTSdir$ = "C:/Documents and Settings/All Users/Application Data/'sgc2.demoAppName$'/TTS"
171 sgc2.synthesizer = -1
172 sgc.alignedTextGrid = -1
174 ##############################################################
176 config.shuffleLists = 1
177 config.adaptiveLists = 0
179 defaultFont$ = "Helvetica"
182 # Set up directories if they do not exist already
183 call set_up_directories
185 # Get saved preferences
186 call read_preferences ""
189 speakCommandDir$ = "'preferencesAppDir$'/TTS"
190 speakCommandFile$ = ""
191 # Define a Praat TTS command that will set sgc2.synthesizer
192 call set_TTS_parameters
194 sgc.recordCommandFile$ = ""
195 sgc.playCommandFile$ = ""
197 sgc.scratchAudioDir$ = "'preferencesAppDir$'\audio\"
199 sgc.scratchAudioDir$ = "/tmp/SpeakGoodChinese/"
201 sgc.useAlternativeRecorder = 0
203 sgc.useAlternativePlayer = 0
206 # Set inital language
207 call set_language 'config.language$'
210 call load_word_list "'localWordlistDir$'" 0
212 # Set up evaluation table
213 initialiseSGC2.toneevaluation_table$ = ""
214 call initialize_toneevaluation_tables
219 ###############################################################
221 # Obligatory procedures
223 ###############################################################
224 # Initialize Demo Window
225 procedure init_window
227 demo Line width... 'defaultLineWidth'
229 call set_font_size 'defaultFontSize'
232 # If there is no recorded sound, try to read stored recording
233 if recordedSound$ = "" and sgc.saveAudio$ <> ""
235 select sgc.currentWordlist
236 if sgc.currentWord > 0 and sgc.currentWord <= sgc.numberOfWords
237 call readPinyin 'sgc.currentWord'
238 sgc.pinyin$ = readPinyin.pinyin$
239 sgc.character$ = readPinyin.character$
240 .outputName$ = "'sgc.saveAudio$'/'sgc.pinyin$'.wav"
241 if fileReadable(.outputName$)
242 sgc.recordedSound = Read from file: .outputName$
243 recordedSound$ = selected$("Sound")
245 # See feedback on earl;ier recorded words
246 if fileReadable("'sgc.saveAudio$'/TestSpeakGoodChinese2.txt")
247 call write_feedback Feedback
249 call write_grade 'sgc.pinyin$'
251 select Table Feedback
254 # Set config.audioName
255 .tmp$ = replace_regex$(sgc.saveAudio$, "[^/\\]+[/\\]?$", "", 0)
256 config.audioName$ = replace$(sgc.saveAudio$, .tmp$, "", 0)
262 # Set mainPage.saveAudio$ grade
263 call set_grade_display 'sgc.pinyin$'
267 .windowTitle$ = replace$(wordlistName$, "_", " ", 0)
268 call set_window_title 'buttons$' '.windowTitle$'
269 # Display the word-list
271 # Wipe screen and draw background
272 call wipeArea 'wipeContourArea$'
273 if config.showBackground
274 call draw_background Background
276 # Define buttons in a table
282 call draw_tone_contour
284 call paint_saveAudio_light
287 sgc.failedAttempts = 0
290 # Make sure all Preferences directories are available
291 procedure set_up_directories
292 .dirPath$ = "'preferencesAppDir$'"
293 createDirectory(.dirPath$)
294 .dirPath$ > '.dirPath$'/directory.txt
295 createDirectory("'.dirPath$'/wordlists")
296 .dirPath$ > '.dirPath$'/wordlists/directory.txt
297 createDirectory("'.dirPath$'/pitchmodels")
298 .dirPath$ > '.dirPath$'/pitchmodels/directory.txt
299 createDirectory("'.dirPath$'/log")
300 .dirPath$ > '.dirPath$'/log/directory.txt
301 createDirectory("'.dirPath$'/TTS")
302 .dirPath$ > '.dirPath$'/TTS/directory.txt
306 # Retrieve and store setting between sessions
308 procedure read_preferences .preferencesFile$
309 if not fileReadable(.preferencesFile$)
310 .preferencesFile$ = preferencesAppFile$
312 if fileReadable(.preferencesFile$)
313 Read from file... 'preferencesAppFile$'
314 .preferenceTable$ = selected$("Table")
315 .numPrefKeys = Get number of rows
316 for .row to .numPrefKeys
317 .variableName$ = Get value... '.row' Key
318 if variableExists(.variableName$)
319 .variableValue = Get value... '.row' Value
320 if .variableValue <> undefined
321 '.variableName$' = '.variableValue'
323 elsif variableExists(.variableName$+"$")
324 .variableValue$ = Get value... '.row' Value
325 .variableName$ = .variableName$+"$"
326 '.variableName$' = "'.variableValue$'"
330 select Table '.preferenceTable$'
335 procedure write_preferences .preferencesFile$
336 Create Table with column names... Preferences 0 Key Value
337 if index_regex(.preferencesFile$, "[a-zA-Z0-9]") <= 0
338 .preferencesFile$ = preferencesAppFile$
342 for .tableNum from 1 to 2
348 .varPrefix$ = replace_regex$(.table$, "^(.)", "\l\1", 0)
350 select Table '.table$'
351 .numTableRows = Get number of rows
352 for .tablerow to .numTableRows
353 select Table '.table$'
354 .label$ = Get value... '.tablerow' Label
355 .variableName$ = .varPrefix$+"."+(replace_regex$(.label$, "^(.)", "\l\1", 0))
356 .keyName$ = .variableName$
358 if sgc.nonPreferences$ <> "" and index(sgc.nonPreferences$, " '.variableName$' ")
360 elsif variableExists(.variableName$)
361 .value = '.variableName$'
363 elsif variableExists(.variableName$ + "$")
364 .variableName$ = .variableName$ + "$"
365 .value$ = '.variableName$'
366 elsif index(.variableName$, "_") > 0
367 .variableName$ = left$(.variableName$, rindex(.variableName$, "_") - 1)
368 .keyName$ = .variableName$
369 select Table Preferences
370 .prefRow = Search column... Key '.keyName$'
372 if variableExists(.variableName$)
373 .value = '.variableName$'
375 elsif variableExists(.variableName$ + "$")
376 .variableName$ = .variableName$ + "$"
377 .value$ = '.variableName$'
383 select Table Preferences
386 Set string value... '.row' Key '.keyName$'
387 Set string value... '.row' Value '.value$'
392 # Some extra settings
393 select Table Preferences
396 Set string value... '.row' Key wordlistDir
397 Set string value... '.row' Value 'localWordlistDir$'
399 select Table Preferences
402 Set string value... '.row' Key wordlistName
403 Set string value... '.row' Value 'wordlistName$'
405 select Table Preferences
406 Write to table file... '.preferencesFile$'
411 ###############################################################
413 # TTS (speech synthesis). Place commands in user info
416 # speakCommandDir$ = "'preferencesAppDir$'/TTS"
417 # speakCommandFile$ = ""
419 # Make sure sgc2.synthesizer is set!
420 procedure create_default_TTS .language$ .voice$ .samplefreq .gap .pitch_adj .pitch_range .words_per_minute .use_data$ .espeak_phones$
421 sgc2.synthesizer = Create SpeechSynthesizer... '.language$' '.voice$'
422 Set speech output settings... .samplefreq .gap .pitch_adj .pitch_range .words_per_minute '.use_data$' '.espeak_phones$'
426 if sgc2.synthesizer > 0
427 select sgc2.synthesizer
429 sgc2.synthesizer = -1
431 # Note, the TTScommand must set sgc2.synthesizer!
432 if config.strict$ = "'sgc.highestLevel'"
433 'sgc2.advancedTTScommand$'
435 'sgc2.normalTTScommand$'
439 .ttscommand$ = "speak"
443 .ttscommand$ = "espeak"
447 .ttscommand$ = "C:/Program Files/eSpeak/command_line/espeak.exe"
451 # Global TTS command has precedence
452 if fileReadable("'globalTTSdir$'/TTS_'.osName$'_command.txt")
453 speakCommandFile$ = "'globalTTSdir$'/TTS_'.osName$'_command.txt"
454 if config.synthesis$ = "_DISABLED_"
456 config.synthesis$ = "eSpeak"
460 # Local TTS command, if there is no global one
461 # Command does not exist yet, create it if eSpeak is installed
462 # Make sure to quote the path!
463 if speakCommandFile$ = ""
464 # Autodetect synthesizer command
465 # if not fileReadable("'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt")
466 # .command_path$ = ""
468 # system_nocheck PATH=${PATH}:/opt/local/bin; bash -c -- 'which '.ttscommand$' > "'speakCommandDir$'/command_path.txt"'
469 # .command_path$ < 'speakCommandDir$'/command_path.txt
471 # system_nocheck PATH=${PATH};bash -c -- 'which '.ttscommand$' > "'speakCommandDir$'/command_path.txt"'
472 # .command_path$ < 'speakCommandDir$'/command_path.txt
474 # if fileReadable(.ttscommand$)
475 # .command_path$ = .ttscommand$
478 # # Remove any newlines
479 # .command_path$ = replace$(.command_path$, "'newline$'", "", 0)
481 # # Command path found
482 # if sgc2.synthesizer <= 0 and .command_path$ <> "" and fileReadable(.command_path$)
483 # deleteFile("'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt")
484 # fileappend "'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt"
485 # ...'.quote$''.ttscommand$''.quote$' -v zh+f4 -s 100 'newline$'
486 # speakCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt"
489 if fileReadable("'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt")
490 speakCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt"
492 deleteFile("'speakCommandDir$'/command_path.txt")
495 # Close off (other TTS maybe a later option)
496 if sgc2.synthesizer > 0 or (speakCommandFile$ <> "" and fileReadable(speakCommandFile$))
497 config.synthesis$ = "eSpeak"
501 procedure set_TTS_parameters
503 .voice$ = replace_regex$(config.voicesTTS$, "^(\S+\s+){'config.voice'}(\S+)(\s+.*)?$", "\2", 0)
505 .voice$ = replace_regex$(config.voicesTTS$, "^(\S+)(\s+.*)?$", "\1", 0)
507 if .voice$ <> "" and index_regex(.voice$, "\s") <= 0
508 if .voice$ = "default"
511 config.voice$ = replace_regex$(.voice$, ".", "\u&", 0)
513 sgc2.normalTTScommand$ = "call create_default_TTS Mandarin '.voice$' 10000 0.01 50 100 95 no IPA"
514 sgc2.advancedTTScommand$ = "call create_default_TTS Mandarin '.voice$' 10000 0.01 50 70 125 no IPA"
516 if macintosh and fileReadable("/usr/bin/say")
517 sgc.nativeTTScommand$ = sgc.nativeOSXTTScommand$
518 elsif unix and fileReadable("/usr/bin/spd-say")
519 sgc.nativeTTScommand$ = sgc.nativeLinuxTTScommand$
521 sgc.nativeTTScommand$ = sgc.nativeWindowsTTScommand$
525 # Alternative audio recorder
526 procedure set_up_recorder
537 # Global TTS command has precedence
538 sgc.useAlternativeRecorder = 0
539 if fileReadable("'globalTTSdir$'/TTS_'.osName$'_record_command.txt")
540 createDirectory(sgc.scratchAudioDir$)
541 sgc.recordCommandFile$ = "'globalTTSdir$'/TTS_'.osName$'_record_command.txt"
542 sgc.useAlternativeRecorder = 1
543 elsif fileReadable("'speakCommandDir$'/TTS_'.osName$'_record_command.txt")
544 createDirectory(sgc.scratchAudioDir$)
545 sgc.recordCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_record_command.txt"
546 sgc.useAlternativeRecorder = 1
550 # Alternative audio player
551 procedure set_up_player
562 # Global TTS command has precedence
563 sgc.useAlternativePlayer = 0
564 if fileReadable("'globalTTSdir$'/TTS_'.osName$'_play_command.txt")
565 createDirectory(sgc.scratchAudioDir$)
566 sgc.playCommandFile$ = "'globalTTSdir$'/TTS_'.osName$'_play_command.txt"
567 sgc.useAlternativePlayer = 1
568 elsif fileReadable("'speakCommandDir$'/TTS_'.osName$'_play_command.txt")
569 createDirectory(sgc.scratchAudioDir$)
570 sgc.playCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_play_command.txt"
571 sgc.useAlternativePlayer = 1
575 ###############################################################
580 # initialiseSGC2.toneevaluation_table$ = ""
581 procedure initialize_toneevaluation_tables
583 if initialiseSGC2.toneevaluation_table$ != ""
584 select sgc2.performanceTable
587 initialiseSGC2.toneevaluation_table$ = ""
588 # Get the name of the table
589 call get_evaluation_table_labels 'config.language$'
590 performanceTableName$ = eval.performance$
592 if sgc.savePerf$ <> "" and fileReadable(sgc.savePerf$)
593 sgc2.performanceTable = Read Table from tab-separated file: sgc.savePerf$
594 Rename: performanceTableName$
595 # Check to make sure all columns are initialized, but only if Pinyin exists!
596 select sgc2.performanceTable
597 .column = Get column index: eval.pinyin$
599 select sgc2.performanceTable
601 sgc2.performanceTable = Create Table with column names... "'performanceTableName$'" 0 'eval.pinyin$' 'eval.correct$' 'eval.wrong$' 'eval.total$' 'eval.high$' 'eval.low$' 'eval.wide$' 'eval.narrow$' 'eval.unknown$' 'eval.commented$' 'eval.level$' 'eval.time$' 'eval.wordlist$'
603 .columnNameList$ = "'eval.correct$' 'eval.wrong$' 'eval.total$' 'eval.high$' 'eval.low$' 'eval.wide$' 'eval.narrow$' 'eval.unknown$' 'eval.commented$' 'eval.level$' 'eval.time$' 'eval.wordlist$'"
604 while index_regex(.columnNameList$, "\S")
605 .columnNameList$ = replace_regex$(.columnNameList$, "^\s+", "", 1)
606 .columnHeader$ = extractWord$(.columnNameList$, "")
607 .columnNameList$ = replace_regex$(.columnNameList$, "^\s*'.columnHeader$'\s*", "", 1)
609 select sgc2.performanceTable
610 .column = Get column index: .columnHeader$
612 select sgc2.performanceTable
613 Append column: .columnHeader$
618 # Performance table has been read. Set the wordlist to the first row
619 select sgc2.performanceTable
620 .numWords = Get number of rows
623 while .row <= .numWords and wordlistName$ = ""
624 wordlistName$ = Get value: .row, eval.wordlist$
628 call load_word_list: localWordlistDir$, 0
631 sgc2.performanceTable = Create Table with column names... "'performanceTableName$'" 0 'eval.pinyin$' 'eval.correct$' 'eval.wrong$' 'eval.total$' 'eval.high$' 'eval.low$' 'eval.wide$' 'eval.narrow$' 'eval.unknown$' 'eval.commented$' 'eval.level$' 'eval.time$' 'eval.wordlist$'
633 initialiseSGC2.toneevaluation_table$ = performanceTableName$
634 call get_toneevaluation_row 'eval.total$'
637 procedure get_toneevaluation_row .pinyin$
638 select sgc2.performanceTable
639 .row = Search column... "'eval.pinyin$'" '.pinyin$'
642 .row = Get number of rows
643 Set string value... '.row' "'eval.pinyin$'" '.pinyin$'
644 Set numeric value... '.row' 'eval.correct$' 0
645 Set numeric value... '.row' 'eval.wrong$' 0
646 Set numeric value... '.row' 'eval.total$' 0
647 Set numeric value... '.row' 'eval.high$' 0
648 Set numeric value... '.row' 'eval.low$' 0
649 Set numeric value... '.row' 'eval.wide$' 0
650 Set numeric value... '.row' 'eval.narrow$' 0
651 Set numeric value... '.row' 'eval.unknown$' 0
652 Set numeric value... '.row' 'eval.commented$' 0
653 Set numeric value... '.row' 'eval.level$' 0
654 Set numeric value... '.row' 'eval.time$' 0
655 Set string value... '.row' 'eval.wordlist$' 'wordlistName$'
656 Sort rows... 'eval.pinyin$'
657 .row = Search column... "'eval.pinyin$'" '.pinyin$'
661 procedure increment_toneevaluation_in_row .row .column$
662 select sgc2.performanceTable
663 .tmp = Get value... '.row' '.column$'
668 Set numeric value... '.row' '.column$' '.tmp'
671 Set string value: .row, eval.level$, config.strict$
673 # Set time stamp and wordlist
675 Set string value: .row, eval.time$, .dateTime$
676 Set string value: .row, eval.wordlist$, wordlistName$
680 # Update existing performance file with toneevaluation
681 procedure update_toneevaluation_file
682 if sgc.savePerf$ <> "" and fileReadable(sgc.savePerf$) and initialiseSGC2.toneevaluation_table$ <> ""
683 select sgc2.performanceTable
684 Write to table file... 'sgc.savePerf$'
688 procedure increment_toneevaluation_value .pinyin$ .column$
689 call get_toneevaluation_row '.pinyin$'
690 .row = get_toneevaluation_row.row
691 call increment_toneevaluation_in_row '.row' '.column$'
693 call get_toneevaluation_row 'eval.total$'
694 .row = get_toneevaluation_row.row
695 call increment_toneevaluation_in_row '.row' '.column$'
698 procedure add_feedback_to_toneevaluation .table$
699 select Table '.table$'
700 .line1$ = Get value... 1 Text
701 .line2$ = Get value... 2 Text
702 .label$ = Get value... 3 Text
704 .label$ = "'eval.unknown$'"
707 .tones$ = replace_regex$(left$(.line1$, rindex(.line1$, ":")), "[^0-9]", "", 0)
708 .recognized$ = replace_regex$(right$(.line1$, length(.line1$)-rindex(.line1$, ":")), "[^0-9]", "", 0)
711 call increment_toneevaluation_value 'sgc.pinyin$' 'eval.total$'
712 if .tones$ = .recognized$
713 call increment_toneevaluation_value 'sgc.pinyin$' 'eval.correct$'
716 call increment_toneevaluation_value 'sgc.pinyin$' 'eval.wrong$'
719 if index_regex(.label$, "(Correct|Wrong)") <= 0
720 if .label$ = "Correct"
721 .label$ = eval.correct$
723 .label$ = eval.wrong$
725 call increment_toneevaluation_value 'sgc.pinyin$' '.label$'
726 call increment_toneevaluation_value 'sgc.pinyin$' 'eval.commented$'
730 # Update performance table when SaveAudio is on
732 call update_toneevaluation_file
736 procedure setGrade .grade$
737 select sgc.currentWordlist
738 if recordedSound$ <> "" and sgc.pinyin$ <> ""
739 call get_toneevaluation_row 'sgc.pinyin$'
740 .row = get_toneevaluation_row.row
741 select sgc2.performanceTable
742 .col = Get column index... Grade
744 Insert column... 2 Grade
747 Set numeric value: .row, "Grade", '.grade$'
748 .numRows = Get number of rows
751 for .r from 2 to .numRows
752 .tmp = Get value: .r, "Grade"
760 .meanGrade = .sumGrade / .sumN
762 Set numeric value: 1, "Grade", .meanGrade
764 # Store current performance table
765 call update_toneevaluation_file
769 procedure getGrade .pinyin$
772 call get_toneevaluation_row '.pinyin$'
773 .row = get_toneevaluation_row.row
775 select sgc2.performanceTable
776 .col = Get column index... Grade
778 Insert column... 2 Grade
780 .grade = Get value: .row, "Grade"
781 if .grade = undefined
788 # Set mainPage.saveAudio$ to Grade
789 procedure set_grade_display .pinyin$
790 mainPage.saveAudio$ = ""
791 select sgc2.performanceTable
793 .col = Get column index: "Grade"
794 if .pinyin$ <> "" and .col > 0
795 call get_toneevaluation_row '.pinyin$'
796 .row = get_toneevaluation_row.row
798 .grade$ = Get value: .row, "Grade"
799 if index_regex(.grade$, "[0-9]") <= 0
805 mainPage.saveAudio$ = .grade$
809 ###############################################################
811 # Miscelaneous procedures
813 ###############################################################
816 procedure synthesize_sound .pinyin$ .character$
817 .pinyin$ = replace_regex$(.pinyin$, "(^""|""$)", "", 0)
818 .character$ = replace_regex$(.character$, "(^""|""$)", "", 0)
819 .pinyinText$ = replace_regex$(.pinyin$, "0", "5", 0)
820 .pinyinExpanded$ = replace_regex$(.pinyin$, "([0-5])", " \1 - ", 0)
821 .pinyinExpanded$ = replace_regex$(.pinyinExpanded$, " - $", "", 0)
823 if .character$ = "-" or .character$ = "" or .character$ = "?"
824 .character$ = .pinyinText$
826 .currentCommand$ = ""
827 # Files need more checks!
828 if speakCommandFile$ <> "" and fileReadable(speakCommandFile$)
829 .currentCommand$ < 'speakCommandFile$'
830 .currentCommand$ = replace$(.currentCommand$, "'newline$'", " ", 0)
831 if index(.currentCommand$, "$$$") and .character$ <> .pinyinText$
832 # Find the character representation
833 .currentCommand$ = replace$(.currentCommand$, "$$$", .character$, 0)
834 elsif index(.currentCommand$, "&&&")
835 # Find the character representation
836 .currentCommand$ = replace$(.currentCommand$, "&&&", .pinyinText$, 0)
837 elsif index(sgc.nativeTTScommand$, "@@@")
838 .currentCommand$ = replace$(sgc.nativeTTScommand$, "@@@", .pinyinExpanded$, 0)
840 .currentCommand$ = .currentCommand$ + " ""'.pinyinText$'"""
843 system_nocheck PATH=${PATH}:/usr/local/bin:/opt/local/bin; bash -rc -- ''.currentCommand$''
845 system_nocheck bash -rc -- ''.currentCommand$''
847 runSystem_nocheck: .currentCommand$
849 elsif sgc.nativeTTScommand$ <> "" and config.voice <= 0
850 # Get the pinyin text on the correct place
851 if index(sgc.nativeTTScommand$, "$$$")
852 .currentCommand$ = replace$(sgc.nativeTTScommand$, "$$$", .character$, 0)
853 elsif index(sgc.nativeTTScommand$, "&&&")
854 .currentCommand$ = replace$(sgc.nativeTTScommand$, "&&&", .pinyinText$, 0)
855 elsif index(sgc.nativeTTScommand$, "@@@")
856 .currentCommand$ = replace$(sgc.nativeTTScommand$, "@@@", .pinyinExpanded$, 0)
858 .currentCommand$ = sgc.nativeTTScommand$ + " ""'.pinyinText$'"""
860 runSystem_nocheck: .currentCommand$
861 elsif sgc2.synthesizer > 0
862 select sgc2.synthesizer
863 Play text... '.pinyin$'
867 procedure align_recordedSound .pinyin$
868 if 0 and sgc2.synthesizer > 0 and recordedSound$ <> ""
869 select Sound 'recordedSound$'
870 .recordedTextGrid = To TextGrid... pinyin
871 Set interval text... 1 1 '.pinyin$'
872 select sgc2.synthesizer
873 plus Sound 'recordedSound$'
874 plus .recordedTextGrid
875 sgc.alignedTextGrid = nowarn noprogress To TextGrid (align,trim)... 1 1 1 -35 0.1 0.1 0.08
876 Rename... AlignedTextGrid
877 select .recordedTextGrid