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.nativeTTScommand$ = ""
101 config.clearSummary = 0
102 config.audioName$ = ""
105 mainPage.saveAudio$ = ""
106 sgc.allWordLists = -1
108 sgc_ToneProt.minimumPitch = 40
109 sgc_ToneProt.maximumPitch = 600
111 # Platform dependent settings
112 if macintosh or windows
113 config.displayChar = 1
114 config.displayNumbers = 0
116 if windows and endsWith(build_SHA$, " XP")
117 config.displayChar = 0
118 config.displayNumbers = 0
121 config.displayChar = 0
122 config.displayNumbers = 0
126 samplingFrequency = 44100
128 samplingFrequency = 44100
130 samplingFrequency = 44100
134 # Be careful: Logging and Replaying can have side-effects
135 # sgc2.logging$ = "call saveLogOfActivity"
137 # When this is not "# ", the command 'replaySGC2Log$' will be run!
138 if not variableExists("replaySGC2Log$")
139 replaySGC2Log$ = "# "
142 config.language$ = "EN"
143 config.register = 249
144 preferencesAppFile$ = preferencesAppDir$+"/sgc2rc.txt"
145 preferencesLogDir$ = "'preferencesAppDir$'/log"
146 preferencesTableDir$ = "'preferencesAppDir$'/GUI"
147 sgc2wordlists$ = "'preferencesAppDir$'/wordlists"
148 localWordlistDir$ = sgc2wordlists$
150 # Global word lists must be installed BY THE ADMINISTRATOR
151 # This means, create the directory 'globalwordlists$' and
152 # fill it with wordlist directories containing wordlist.Table
153 # and audio files. They can be copied from a local directory.
154 globalwordlists$ = ""
155 globaltablelists$ = ""
158 globalwordlists$ = "/etc/'sgc2.demoAppName$'/wordlists"
159 globaltablelists$ = "/etc/'sgc2.demoAppName$'/GUI"
160 globalTTSdir$ = "/etc/'sgc2.demoAppName$'/TTS"
162 globalwordlists$ = "/Library/Preferences/'sgc2.demoAppName$'/wordlists"
163 globaltablelists$ = "/Library/Preferences/'sgc2.demoAppName$'/GUI"
164 globalTTSdir$ = "/Library/Preferences/'sgc2.demoAppName$'/TTS"
166 globalwordlists$ = "C:/Documents and Settings/All Users/Application Data/'sgc2.demoAppName$'/wordlists"
167 globaltablelists$ = "C:/Documents and Settings/All Users/Application Data/'sgc2.demoAppName$'/GUI"
168 globalTTSdir$ = "C:/Documents and Settings/All Users/Application Data/'sgc2.demoAppName$'/TTS"
170 sgc2.synthesizer = -1
171 sgc.alignedTextGrid = -1
173 ##############################################################
175 config.shuffleLists = 1
176 config.adaptiveLists = 0
178 defaultFont$ = "Helvetica"
181 # Set up directories if they do not exist already
182 call set_up_directories
184 # Get saved preferences
185 call read_preferences ""
188 speakCommandDir$ = "'preferencesAppDir$'/TTS"
189 speakCommandFile$ = ""
190 # Define a Praat TTS command that will set sgc2.synthesizer
191 call set_TTS_parameters
193 sgc.recordCommandFile$ = ""
194 sgc.playCommandFile$ = ""
196 sgc.scratchAudioDir$ = "'preferencesAppDir$'\audio\"
198 sgc.scratchAudioDir$ = "/tmp/SpeakGoodChinese/"
200 sgc.useAlternativeRecorder = 0
202 sgc.useAlternativePlayer = 0
205 # Set inital language
206 call set_language 'config.language$'
209 call load_word_list "'localWordlistDir$'" 0
211 # Set up evaluation table
212 initialiseSGC2.toneevaluation_table$ = ""
213 call initialize_toneevaluation_tables
218 ###############################################################
220 # Obligatory procedures
222 ###############################################################
223 # Initialize Demo Window
224 procedure init_window
226 demo Line width... 'defaultLineWidth'
228 call set_font_size 'defaultFontSize'
231 # If there is no recorded sound, try to read stored recording
232 if recordedSound$ = "" and sgc.saveAudio$ <> ""
234 select sgc.currentWordlist
235 if sgc.currentWord > 0 and sgc.currentWord <= sgc.numberOfWords
236 call readPinyin 'sgc.currentWord'
237 sgc.pinyin$ = readPinyin.pinyin$
238 .outputName$ = "'sgc.saveAudio$'/'sgc.pinyin$'.wav"
239 if fileReadable(.outputName$)
240 sgc.recordedSound = Read from file: .outputName$
241 recordedSound$ = selected$("Sound")
243 # See feedback on earl;ier recorded words
244 if fileReadable("'sgc.saveAudio$'/TestSpeakGoodChinese2.txt")
245 call write_feedback Feedback
247 select Table Feedback
250 # Set config.audioName
251 .tmp$ = replace_regex$(sgc.saveAudio$, "[^/\\]+[/\\]?$", "", 0)
252 config.audioName$ = replace$(sgc.saveAudio$, .tmp$, "", 0)
258 # Set mainPage.saveAudio$ grade
259 call set_grade_display 'sgc.pinyin$'
263 .windowTitle$ = replace$(wordlistName$, "_", " ", 0)
264 call set_window_title 'buttons$' '.windowTitle$'
265 # Display the word-list
267 # Wipe screen and draw background
268 call wipeArea 'wipeContourArea$'
269 if config.showBackground
270 call draw_background Background
272 # Define buttons in a table
278 call draw_tone_contour
280 call paint_saveAudio_light
283 sgc.failedAttempts = 0
286 # Make sure all Preferences directories are available
287 procedure set_up_directories
288 .dirPath$ = "'preferencesAppDir$'"
289 createDirectory(.dirPath$)
290 .dirPath$ > '.dirPath$'/directory.txt
291 createDirectory("'.dirPath$'/wordlists")
292 .dirPath$ > '.dirPath$'/wordlists/directory.txt
293 createDirectory("'.dirPath$'/pitchmodels")
294 .dirPath$ > '.dirPath$'/pitchmodels/directory.txt
295 createDirectory("'.dirPath$'/log")
296 .dirPath$ > '.dirPath$'/log/directory.txt
297 createDirectory("'.dirPath$'/TTS")
298 .dirPath$ > '.dirPath$'/TTS/directory.txt
302 # Retrieve and store setting between sessions
304 procedure read_preferences .preferencesFile$
305 if not fileReadable(.preferencesFile$)
306 .preferencesFile$ = preferencesAppFile$
308 if fileReadable(.preferencesFile$)
309 Read from file... 'preferencesAppFile$'
310 .preferenceTable$ = selected$("Table")
311 .numPrefKeys = Get number of rows
312 for .row to .numPrefKeys
313 .variableName$ = Get value... '.row' Key
314 if variableExists(.variableName$)
315 .variableValue = Get value... '.row' Value
316 if .variableValue <> undefined
317 '.variableName$' = '.variableValue'
319 elsif variableExists(.variableName$+"$")
320 .variableValue$ = Get value... '.row' Value
321 .variableName$ = .variableName$+"$"
322 '.variableName$' = "'.variableValue$'"
326 select Table '.preferenceTable$'
331 procedure write_preferences .preferencesFile$
332 Create Table with column names... Preferences 0 Key Value
333 if index_regex(.preferencesFile$, "[a-zA-Z0-9]") <= 0
334 .preferencesFile$ = preferencesAppFile$
338 for .tableNum from 1 to 2
344 .varPrefix$ = replace_regex$(.table$, "^(.)", "\l\1", 0)
346 select Table '.table$'
347 .numTableRows = Get number of rows
348 for .tablerow to .numTableRows
349 select Table '.table$'
350 .label$ = Get value... '.tablerow' Label
351 .variableName$ = .varPrefix$+"."+(replace_regex$(.label$, "^(.)", "\l\1", 0))
352 .keyName$ = .variableName$
354 if sgc.nonPreferences$ <> "" and index(sgc.nonPreferences$, " '.variableName$' ")
356 elsif variableExists(.variableName$)
357 .value = '.variableName$'
359 elsif variableExists(.variableName$ + "$")
360 .variableName$ = .variableName$ + "$"
361 .value$ = '.variableName$'
362 elsif index(.variableName$, "_") > 0
363 .variableName$ = left$(.variableName$, rindex(.variableName$, "_") - 1)
364 .keyName$ = .variableName$
365 select Table Preferences
366 .prefRow = Search column... Key '.keyName$'
368 if variableExists(.variableName$)
369 .value = '.variableName$'
371 elsif variableExists(.variableName$ + "$")
372 .variableName$ = .variableName$ + "$"
373 .value$ = '.variableName$'
379 select Table Preferences
382 Set string value... '.row' Key '.keyName$'
383 Set string value... '.row' Value '.value$'
388 # Some extra settings
389 select Table Preferences
392 Set string value... '.row' Key wordlistDir
393 Set string value... '.row' Value 'localWordlistDir$'
395 select Table Preferences
398 Set string value... '.row' Key wordlistName
399 Set string value... '.row' Value 'wordlistName$'
401 select Table Preferences
402 Write to table file... '.preferencesFile$'
407 ###############################################################
409 # TTS (speech synthesis). Place commands in user info
412 # speakCommandDir$ = "'preferencesAppDir$'/TTS"
413 # speakCommandFile$ = ""
415 # Make sure sgc2.synthesizer is set!
416 procedure create_default_TTS .language$ .voice$ .samplefreq .gap .pitch_adj .pitch_range .words_per_minute .use_data$ .espeak_phones$
417 sgc2.synthesizer = Create SpeechSynthesizer... '.language$' '.voice$'
418 Set speech output settings... .samplefreq .gap .pitch_adj .pitch_range .words_per_minute '.use_data$' '.espeak_phones$'
422 if sgc2.synthesizer > 0
423 select sgc2.synthesizer
425 sgc2.synthesizer = -1
427 # Note, the TTScommand must set sgc2.synthesizer!
428 if config.strict$ = "'sgc.highestLevel'"
429 'sgc2.advancedTTScommand$'
431 'sgc2.normalTTScommand$'
435 .ttscommand$ = "speak"
439 .ttscommand$ = "espeak"
443 .ttscommand$ = "C:/Program Files/eSpeak/command_line/espeak.exe"
447 # Global TTS command has precedence
448 if fileReadable("'globalTTSdir$'/TTS_'.osName$'_command.txt")
449 speakCommandFile$ = "'globalTTSdir$'/TTS_'.osName$'_command.txt"
450 if config.synthesis$ = "_DISABLED_"
452 config.synthesis$ = "eSpeak"
456 # Local TTS command, if there is no global one
457 # Command does not exist yet, create it if eSpeak is installed
458 # Make sure to quote the path!
459 if speakCommandFile$ = ""
460 # Autodetect synthesizer command
461 # if not fileReadable("'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt")
462 # .command_path$ = ""
464 # system_nocheck PATH=${PATH}:/opt/local/bin; bash -c -- 'which '.ttscommand$' > "'speakCommandDir$'/command_path.txt"'
465 # .command_path$ < 'speakCommandDir$'/command_path.txt
467 # system_nocheck PATH=${PATH};bash -c -- 'which '.ttscommand$' > "'speakCommandDir$'/command_path.txt"'
468 # .command_path$ < 'speakCommandDir$'/command_path.txt
470 # if fileReadable(.ttscommand$)
471 # .command_path$ = .ttscommand$
474 # # Remove any newlines
475 # .command_path$ = replace$(.command_path$, "'newline$'", "", 0)
477 # # Command path found
478 # if sgc2.synthesizer <= 0 and .command_path$ <> "" and fileReadable(.command_path$)
479 # deleteFile("'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt")
480 # fileappend "'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt"
481 # ...'.quote$''.ttscommand$''.quote$' -v zh+f4 -s 100 'newline$'
482 # speakCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt"
485 if fileReadable("'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt")
486 speakCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt"
488 deleteFile("'speakCommandDir$'/command_path.txt")
491 # Close off (other TTS maybe a later option)
492 if sgc2.synthesizer > 0 or (speakCommandFile$ <> "" and fileReadable(speakCommandFile$))
493 config.synthesis$ = "eSpeak"
497 procedure set_TTS_parameters
499 .voice$ = replace_regex$(config.voicesTTS$, "^(\S+\s+){'config.voice'}(\S+)(\s+.*)?$", "\2", 0)
501 .voice$ = replace_regex$(config.voicesTTS$, "^(\S+)(\s+.*)?$", "\1", 0)
503 if .voice$ <> "" and index_regex(.voice$, "\s") <= 0
504 if .voice$ = "default"
507 config.voice$ = replace_regex$(.voice$, ".", "\u&", 0)
509 sgc2.normalTTScommand$ = "call create_default_TTS Mandarin '.voice$' 10000 0.01 50 100 95 no IPA"
510 sgc2.advancedTTScommand$ = "call create_default_TTS Mandarin '.voice$' 10000 0.01 50 70 125 no IPA"
512 if macintosh and fileReadable("/usr/bin/say")
513 sgc.nativeTTScommand$ = sgc.nativeOSXTTScommand$
514 elsif unix and fileReadable("/usr/bin/spd-say")
515 sgc.nativeTTScommand$ = sgc.nativeLinuxTTScommand$
517 sgc.nativeTTScommand$ = sgc.nativeWindowsTTScommand$
521 # Alternative audio recorder
522 procedure set_up_recorder
533 # Global TTS command has precedence
534 sgc.useAlternativeRecorder = 0
535 if fileReadable("'globalTTSdir$'/TTS_'.osName$'_record_command.txt")
536 createDirectory(sgc.scratchAudioDir$)
537 sgc.recordCommandFile$ = "'globalTTSdir$'/TTS_'.osName$'_record_command.txt"
538 sgc.useAlternativeRecorder = 1
539 elsif fileReadable("'speakCommandDir$'/TTS_'.osName$'_record_command.txt")
540 createDirectory(sgc.scratchAudioDir$)
541 sgc.recordCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_record_command.txt"
542 sgc.useAlternativeRecorder = 1
546 # Alternative audio player
547 procedure set_up_player
558 # Global TTS command has precedence
559 sgc.useAlternativePlayer = 0
560 if fileReadable("'globalTTSdir$'/TTS_'.osName$'_play_command.txt")
561 createDirectory(sgc.scratchAudioDir$)
562 sgc.playCommandFile$ = "'globalTTSdir$'/TTS_'.osName$'_play_command.txt"
563 sgc.useAlternativePlayer = 1
564 elsif fileReadable("'speakCommandDir$'/TTS_'.osName$'_play_command.txt")
565 createDirectory(sgc.scratchAudioDir$)
566 sgc.playCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_play_command.txt"
567 sgc.useAlternativePlayer = 1
571 ###############################################################
576 # initialiseSGC2.toneevaluation_table$ = ""
577 procedure initialize_toneevaluation_tables
579 if initialiseSGC2.toneevaluation_table$ != ""
580 select sgc2.performanceTable
583 initialiseSGC2.toneevaluation_table$ = ""
584 # Get the name of the table
585 call get_evaluation_table_labels 'config.language$'
586 performanceTableName$ = eval.performance$
588 if sgc.savePerf$ <> "" and fileReadable(sgc.savePerf$)
589 sgc2.performanceTable = Read Table from tab-separated file: sgc.savePerf$
590 Rename: performanceTableName$
591 # Check to make sure all columns are initialized, but only if Pinyin exists!
592 select sgc2.performanceTable
593 .column = Get column index: eval.pinyin$
595 select sgc2.performanceTable
597 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$'
599 .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$'"
600 while index_regex(.columnNameList$, "\S")
601 .columnNameList$ = replace_regex$(.columnNameList$, "^\s+", "", 1)
602 .columnHeader$ = extractWord$(.columnNameList$, "")
603 .columnNameList$ = replace_regex$(.columnNameList$, "^\s*'.columnHeader$'\s*", "", 1)
605 select sgc2.performanceTable
606 .column = Get column index: .columnHeader$
608 select sgc2.performanceTable
609 Append column: .columnHeader$
614 # Performance table has been read. Set the wordlist to the first row
615 select sgc2.performanceTable
616 wordlistName$ = Get value: 1, eval.wordlist$
617 call load_word_list: localWordlistDir$, 0
620 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$'
622 initialiseSGC2.toneevaluation_table$ = performanceTableName$
623 call get_toneevaluation_row 'eval.total$'
626 procedure get_toneevaluation_row .pinyin$
627 select sgc2.performanceTable
628 .row = Search column... "'eval.pinyin$'" '.pinyin$'
631 .row = Get number of rows
632 Set string value... '.row' "'eval.pinyin$'" '.pinyin$'
633 Set numeric value... '.row' 'eval.correct$' 0
634 Set numeric value... '.row' 'eval.wrong$' 0
635 Set numeric value... '.row' 'eval.total$' 0
636 Set numeric value... '.row' 'eval.high$' 0
637 Set numeric value... '.row' 'eval.low$' 0
638 Set numeric value... '.row' 'eval.wide$' 0
639 Set numeric value... '.row' 'eval.narrow$' 0
640 Set numeric value... '.row' 'eval.unknown$' 0
641 Set numeric value... '.row' 'eval.commented$' 0
642 Set numeric value... '.row' 'eval.level$' 0
643 Set numeric value... '.row' 'eval.time$' 0
644 Set string value... '.row' 'eval.wordlist$' 'wordlistName$'
645 Sort rows... 'eval.pinyin$'
646 .row = Search column... "'eval.pinyin$'" '.pinyin$'
650 procedure increment_toneevaluation_in_row .row .column$
651 select sgc2.performanceTable
652 .tmp = Get value... '.row' '.column$'
657 Set numeric value... '.row' '.column$' '.tmp'
660 Set string value: .row, eval.level$, config.strict$
662 # Set time stamp and wordlist
664 Set string value: .row, eval.time$, .dateTime$
665 Set string value: .row, eval.wordlist$, wordlistName$
669 # Update existing performance file with toneevaluation
670 procedure update_toneevaluation_file
671 if sgc.savePerf$ <> "" and fileReadable(sgc.savePerf$) and initialiseSGC2.toneevaluation_table$ <> ""
672 select sgc2.performanceTable
673 Write to table file... 'sgc.savePerf$'
677 procedure increment_toneevaluation_value .pinyin$ .column$
678 call get_toneevaluation_row '.pinyin$'
679 .row = get_toneevaluation_row.row
680 call increment_toneevaluation_in_row '.row' '.column$'
682 call get_toneevaluation_row 'eval.total$'
683 .row = get_toneevaluation_row.row
684 call increment_toneevaluation_in_row '.row' '.column$'
687 procedure add_feedback_to_toneevaluation .table$
688 select Table '.table$'
689 .line1$ = Get value... 1 Text
690 .line2$ = Get value... 2 Text
691 .label$ = Get value... 3 Text
693 .label$ = "'eval.unknown$'"
696 .tones$ = replace_regex$(left$(.line1$, rindex(.line1$, ":")), "[^0-9]", "", 0)
697 .recognized$ = replace_regex$(right$(.line1$, length(.line1$)-rindex(.line1$, ":")), "[^0-9]", "", 0)
700 call increment_toneevaluation_value 'sgc.pinyin$' 'eval.total$'
701 if .tones$ = .recognized$
702 call increment_toneevaluation_value 'sgc.pinyin$' 'eval.correct$'
705 call increment_toneevaluation_value 'sgc.pinyin$' 'eval.wrong$'
708 if index_regex(.label$, "(Correct|Wrong)") <= 0
709 if .label$ = "Correct"
710 .label$ = eval.correct$
712 .label$ = eval.wrong$
714 call increment_toneevaluation_value 'sgc.pinyin$' '.label$'
715 call increment_toneevaluation_value 'sgc.pinyin$' 'eval.commented$'
719 # Update performance table when SaveAudio is on
721 call update_toneevaluation_file
725 procedure setGrade .grade$
726 select sgc.currentWordlist
727 if recordedSound$ <> "" and sgc.pinyin$ <> ""
728 call get_toneevaluation_row 'sgc.pinyin$'
729 .row = get_toneevaluation_row.row
730 select sgc2.performanceTable
731 .col = Get column index... Grade
733 Insert column... 2 Grade
736 Set numeric value: .row, "Grade", '.grade$'
737 .numRows = Get number of rows
740 for .r from 2 to .numRows
741 .tmp = Get value: .r, "Grade"
749 .meanGrade = .sumGrade / .sumN
751 Set numeric value: 1, "Grade", .meanGrade
753 # Store current performance table
754 call update_toneevaluation_file
758 # Set mainPage.saveAudio$ to Grade
759 procedure set_grade_display .pinyin$
760 mainPage.saveAudio$ = ""
761 select sgc2.performanceTable
763 .col = Get column index: "Grade"
764 if .pinyin$ <> "" and .col > 0
765 call get_toneevaluation_row '.pinyin$'
766 .row = get_toneevaluation_row.row
768 .grade$ = Get value: .row, "Grade"
769 if index_regex(.grade$, "[0-9]") <= 0
775 mainPage.saveAudio$ = .grade$
779 ###############################################################
781 # Miscelaneous procedures
783 ###############################################################
786 procedure synthesize_sound .pinyin$
788 if speakCommandFile$ <> "" and fileReadable(speakCommandFile$)
789 .command$ < 'speakCommandFile$'
790 .command$ = replace$(.command$, "'newline$'", " ", 0)
792 system_nocheck PATH=${PATH}:/usr/local/bin:/opt/local/bin; bash -rc -- ''.command$' "'.pinyin$'"'
794 system_nocheck bash -rc -- ''.command$' "'.pinyin$'"'
796 system_nocheck call '.command$' "'.pinyin$'"
798 elsif sgc.nativeTTScommand$ <> "" and config.voice <= 0
799 .text$ = replace_regex$(.pinyin$, "0$", "''", 0)
800 # Get the pinyin text on the correct place
801 if index(sgc.nativeTTScommand$, "$$$")
802 .currentCommand$ = replace$(sgc.nativeTTScommand$, "$$$", .text$, 0)
804 .currentCommand$ = sgc.nativeTTScommand$ + " ""'.text$'"""
806 runSystem_nocheck: .currentCommand$
807 elsif sgc2.synthesizer > 0
808 select sgc2.synthesizer
809 Play text... '.pinyin$'
813 procedure align_recordedSound .pinyin$
814 if 0 and sgc2.synthesizer > 0 and recordedSound$ <> ""
815 select Sound 'recordedSound$'
816 .recordedTextGrid = To TextGrid... pinyin
817 Set interval text... 1 1 '.pinyin$'
818 select sgc2.synthesizer
819 plus Sound 'recordedSound$'
820 plus .recordedTextGrid
821 sgc.alignedTextGrid = nowarn noprogress To TextGrid (align,trim)... 1 1 1 -35 0.1 0.1 0.08
822 Rename... AlignedTextGrid
823 select .recordedTextGrid