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.nativeTTScommand$ = ""
100 config.clearSummary = 0
101 config.audioName$ = ""
104 mainPage.saveAudio$ = ""
105 sgc.allWordLists = -1
107 sgc_ToneProt.minimumPitch = 40
108 sgc_ToneProt.maximumPitch = 600
110 # Platform dependent settings
111 if macintosh or windows
112 config.displayChar = 1
113 config.displayNumbers = 0
115 if windows and endsWith(build_SHA$, " XP")
116 config.displayChar = 0
117 config.displayNumbers = 0
120 config.displayChar = 0
121 config.displayNumbers = 0
125 samplingFrequency = 44100
127 samplingFrequency = 44100
129 samplingFrequency = 44100
133 # Be careful: Logging and Replaying can have side-effects
134 # sgc2.logging$ = "call saveLogOfActivity"
136 # When this is not "# ", the command 'replaySGC2Log$' will be run!
137 if not variableExists("replaySGC2Log$")
138 replaySGC2Log$ = "# "
141 config.language$ = "EN"
142 config.register = 249
143 preferencesAppFile$ = preferencesAppDir$+"/sgc2rc.txt"
144 preferencesLogDir$ = "'preferencesAppDir$'/log"
145 preferencesTableDir$ = "'preferencesAppDir$'/GUI"
146 sgc2wordlists$ = "'preferencesAppDir$'/wordlists"
147 localWordlistDir$ = sgc2wordlists$
149 # Global word lists must be installed BY THE ADMINISTRATOR
150 # This means, create the directory 'globalwordlists$' and
151 # fill it with wordlist directories containing wordlist.Table
152 # and audio files. They can be copied from a local directory.
153 globalwordlists$ = ""
154 globaltablelists$ = ""
157 globalwordlists$ = "/etc/'sgc2.demoAppName$'/wordlists"
158 globaltablelists$ = "/etc/'sgc2.demoAppName$'/GUI"
159 globalTTSdir$ = "/etc/'sgc2.demoAppName$'/TTS"
161 globalwordlists$ = "/Library/Preferences/'sgc2.demoAppName$'/wordlists"
162 globaltablelists$ = "/Library/Preferences/'sgc2.demoAppName$'/GUI"
163 globalTTSdir$ = "/Library/Preferences/'sgc2.demoAppName$'/TTS"
165 globalwordlists$ = "C:/Documents and Settings/All Users/Application Data/'sgc2.demoAppName$'/wordlists"
166 globaltablelists$ = "C:/Documents and Settings/All Users/Application Data/'sgc2.demoAppName$'/GUI"
167 globalTTSdir$ = "C:/Documents and Settings/All Users/Application Data/'sgc2.demoAppName$'/TTS"
169 sgc2.synthesizer = -1
170 sgc.alignedTextGrid = -1
172 ##############################################################
174 config.shuffleLists = 1
175 config.adaptiveLists = 0
177 defaultFont$ = "Helvetica"
180 # Set up directories if they do not exist already
181 call set_up_directories
183 # Get saved preferences
184 call read_preferences ""
187 speakCommandDir$ = "'preferencesAppDir$'/TTS"
188 speakCommandFile$ = ""
189 # Define a Praat TTS command that will set sgc2.synthesizer
190 call set_TTS_parameters
192 sgc.recordCommandFile$ = ""
193 sgc.playCommandFile$ = ""
195 sgc.scratchAudioDir$ = "'preferencesAppDir$'\audio\"
197 sgc.scratchAudioDir$ = "/tmp/SpeakGoodChinese/"
199 sgc.useAlternativeRecorder = 0
201 sgc.useAlternativePlayer = 0
204 # Set inital language
205 call set_language 'config.language$'
208 call load_word_list "'localWordlistDir$'" 0
210 # Set up evaluation table
211 initialiseSGC2.toneevaluation_table$ = ""
212 call initialize_toneevaluation_tables
217 ###############################################################
219 # Obligatory procedures
221 ###############################################################
222 # Initialize Demo Window
223 procedure init_window
225 demo Line width... 'defaultLineWidth'
227 call set_font_size 'defaultFontSize'
230 # If there is no recorded sound, try to read stored recording
231 if recordedSound$ = "" and sgc.saveAudio$ <> ""
233 select sgc.currentWordlist
234 if sgc.currentWord > 0 and sgc.currentWord <= sgc.numberOfWords
235 call readPinyin 'sgc.currentWord'
236 sgc.pinyin$ = readPinyin.pinyin$
237 .outputName$ = "'sgc.saveAudio$'/'sgc.pinyin$'.wav"
238 if fileReadable(.outputName$)
239 sgc.recordedSound = Read from file: .outputName$
240 recordedSound$ = selected$("Sound")
242 # See feedback on earl;ier recorded words
243 if fileReadable("'sgc.saveAudio$'/TestSpeakGoodChinese2.txt")
244 call write_feedback Feedback
246 select Table Feedback
249 # Set config.audioName
250 .tmp$ = replace_regex$(sgc.saveAudio$, "[^/\\]+[/\\]?$", "", 0)
251 config.audioName$ = replace$(sgc.saveAudio$, .tmp$, "", 0)
257 # Set mainPage.saveAudio$ grade
258 call set_grade_display 'sgc.pinyin$'
262 .windowTitle$ = replace$(wordlistName$, "_", " ", 0)
263 call set_window_title 'buttons$' '.windowTitle$'
264 # Display the word-list
266 # Wipe screen and draw background
267 call wipeArea 'wipeContourArea$'
268 if config.showBackground
269 call draw_background Background
271 # Define buttons in a table
277 call draw_tone_contour
279 call paint_saveAudio_light
282 sgc.failedAttempts = 0
285 # Make sure all Preferences directories are available
286 procedure set_up_directories
287 .dirPath$ = "'preferencesAppDir$'"
288 createDirectory(.dirPath$)
289 .dirPath$ > '.dirPath$'/directory.txt
290 createDirectory("'.dirPath$'/wordlists")
291 .dirPath$ > '.dirPath$'/wordlists/directory.txt
292 createDirectory("'.dirPath$'/pitchmodels")
293 .dirPath$ > '.dirPath$'/pitchmodels/directory.txt
294 createDirectory("'.dirPath$'/log")
295 .dirPath$ > '.dirPath$'/log/directory.txt
296 createDirectory("'.dirPath$'/TTS")
297 .dirPath$ > '.dirPath$'/TTS/directory.txt
301 # Retrieve and store setting between sessions
303 procedure read_preferences .preferencesFile$
304 if not fileReadable(.preferencesFile$)
305 .preferencesFile$ = preferencesAppFile$
307 if fileReadable(.preferencesFile$)
308 Read from file... 'preferencesAppFile$'
309 .preferenceTable$ = selected$("Table")
310 .numPrefKeys = Get number of rows
311 for .row to .numPrefKeys
312 .variableName$ = Get value... '.row' Key
313 if variableExists(.variableName$)
314 .variableValue = Get value... '.row' Value
315 if .variableValue <> undefined
316 '.variableName$' = '.variableValue'
318 elsif variableExists(.variableName$+"$")
319 .variableValue$ = Get value... '.row' Value
320 .variableName$ = .variableName$+"$"
321 '.variableName$' = "'.variableValue$'"
325 select Table '.preferenceTable$'
330 procedure write_preferences .preferencesFile$
331 Create Table with column names... Preferences 0 Key Value
332 if index_regex(.preferencesFile$, "[a-zA-Z0-9]") <= 0
333 .preferencesFile$ = preferencesAppFile$
337 for .tableNum from 1 to 2
343 .varPrefix$ = replace_regex$(.table$, "^(.)", "\l\1", 0)
345 select Table '.table$'
346 .numTableRows = Get number of rows
347 for .tablerow to .numTableRows
348 select Table '.table$'
349 .label$ = Get value... '.tablerow' Label
350 .variableName$ = .varPrefix$+"."+(replace_regex$(.label$, "^(.)", "\l\1", 0))
351 .keyName$ = .variableName$
353 if sgc.nonPreferences$ <> "" and index(sgc.nonPreferences$, " '.variableName$' ")
355 elsif variableExists(.variableName$)
356 .value = '.variableName$'
358 elsif variableExists(.variableName$ + "$")
359 .variableName$ = .variableName$ + "$"
360 .value$ = '.variableName$'
361 elsif index(.variableName$, "_") > 0
362 .variableName$ = left$(.variableName$, rindex(.variableName$, "_") - 1)
363 .keyName$ = .variableName$
364 select Table Preferences
365 .prefRow = Search column... Key '.keyName$'
367 if variableExists(.variableName$)
368 .value = '.variableName$'
370 elsif variableExists(.variableName$ + "$")
371 .variableName$ = .variableName$ + "$"
372 .value$ = '.variableName$'
378 select Table Preferences
381 Set string value... '.row' Key '.keyName$'
382 Set string value... '.row' Value '.value$'
387 # Some extra settings
388 select Table Preferences
391 Set string value... '.row' Key wordlistDir
392 Set string value... '.row' Value 'localWordlistDir$'
394 select Table Preferences
397 Set string value... '.row' Key wordlistName
398 Set string value... '.row' Value 'wordlistName$'
400 select Table Preferences
401 Write to table file... '.preferencesFile$'
406 ###############################################################
408 # TTS (speech synthesis). Place commands in user info
411 # speakCommandDir$ = "'preferencesAppDir$'/TTS"
412 # speakCommandFile$ = ""
414 # Make sure sgc2.synthesizer is set!
415 procedure create_default_TTS .language$ .voice$ .samplefreq .gap .pitch_adj .pitch_range .words_per_minute .use_data$ .espeak_phones$
416 sgc2.synthesizer = Create SpeechSynthesizer... '.language$' '.voice$'
417 Set speech output settings... .samplefreq .gap .pitch_adj .pitch_range .words_per_minute '.use_data$' '.espeak_phones$'
421 if sgc2.synthesizer > 0
422 select sgc2.synthesizer
424 sgc2.synthesizer = -1
426 # Note, the TTScommand must set sgc2.synthesizer!
427 if config.strict$ = "'sgc.highestLevel'"
428 'sgc2.advancedTTScommand$'
430 'sgc2.normalTTScommand$'
434 .ttscommand$ = "speak"
438 .ttscommand$ = "espeak"
442 .ttscommand$ = "C:/Program Files/eSpeak/command_line/espeak.exe"
446 # Global TTS command has precedence
447 if fileReadable("'globalTTSdir$'/TTS_'.osName$'_command.txt")
448 speakCommandFile$ = "'globalTTSdir$'/TTS_'.osName$'_command.txt"
449 if config.synthesis$ = "_DISABLED_"
451 config.synthesis$ = "eSpeak"
455 # Local TTS command, if there is no global one
456 # Command does not exist yet, create it if eSpeak is installed
457 # Make sure to quote the path!
458 if speakCommandFile$ = ""
459 # Autodetect synthesizer command
460 # if not fileReadable("'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt")
461 # .command_path$ = ""
463 # system_nocheck PATH=${PATH}:/opt/local/bin; bash -c -- 'which '.ttscommand$' > "'speakCommandDir$'/command_path.txt"'
464 # .command_path$ < 'speakCommandDir$'/command_path.txt
466 # system_nocheck PATH=${PATH};bash -c -- 'which '.ttscommand$' > "'speakCommandDir$'/command_path.txt"'
467 # .command_path$ < 'speakCommandDir$'/command_path.txt
469 # if fileReadable(.ttscommand$)
470 # .command_path$ = .ttscommand$
473 # # Remove any newlines
474 # .command_path$ = replace$(.command_path$, "'newline$'", "", 0)
476 # # Command path found
477 # if sgc2.synthesizer <= 0 and .command_path$ <> "" and fileReadable(.command_path$)
478 # deleteFile("'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt")
479 # fileappend "'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt"
480 # ...'.quote$''.ttscommand$''.quote$' -v zh+f4 -s 100 'newline$'
481 # speakCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt"
484 if fileReadable("'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt")
485 speakCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt"
487 deleteFile("'speakCommandDir$'/command_path.txt")
490 # Close off (other TTS maybe a later option)
491 if sgc2.synthesizer > 0 or (speakCommandFile$ <> "" and fileReadable(speakCommandFile$))
492 config.synthesis$ = "eSpeak"
496 procedure set_TTS_parameters
498 .voice$ = replace_regex$(config.voicesTTS$, "^(\S+\s+){'config.voice'}(\S+)(\s+.*)?$", "\2", 0)
500 .voice$ = replace_regex$(config.voicesTTS$, "^(\S+)(\s+.*)?$", "\1", 0)
502 if .voice$ <> "" and index_regex(.voice$, "\s") <= 0
503 if .voice$ = "default"
506 config.voice$ = replace_regex$(.voice$, ".", "\u&", 0)
508 sgc2.normalTTScommand$ = "call create_default_TTS Mandarin '.voice$' 10000 0.01 50 100 95 no IPA"
509 sgc2.advancedTTScommand$ = "call create_default_TTS Mandarin '.voice$' 10000 0.01 50 70 125 no IPA"
511 if macintosh and fileReadable("/usr/bin/say")
512 sgc.nativeTTScommand$ = sgc.nativeOSXTTScommand$
513 elsif unix and fileReadable("/usr/bin/spd-say")
514 sgc.nativeTTScommand$ = sgc.nativeLinuxTTScommand$
518 # Alternative audio recorder
519 procedure set_up_recorder
530 # Global TTS command has precedence
531 sgc.useAlternativeRecorder = 0
532 if fileReadable("'globalTTSdir$'/TTS_'.osName$'_record_command.txt")
533 createDirectory(sgc.scratchAudioDir$)
534 sgc.recordCommandFile$ = "'globalTTSdir$'/TTS_'.osName$'_record_command.txt"
535 sgc.useAlternativeRecorder = 1
536 elsif fileReadable("'speakCommandDir$'/TTS_'.osName$'_record_command.txt")
537 createDirectory(sgc.scratchAudioDir$)
538 sgc.recordCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_record_command.txt"
539 sgc.useAlternativeRecorder = 1
543 # Alternative audio player
544 procedure set_up_player
555 # Global TTS command has precedence
556 sgc.useAlternativePlayer = 0
557 if fileReadable("'globalTTSdir$'/TTS_'.osName$'_play_command.txt")
558 createDirectory(sgc.scratchAudioDir$)
559 sgc.playCommandFile$ = "'globalTTSdir$'/TTS_'.osName$'_play_command.txt"
560 sgc.useAlternativePlayer = 1
561 elsif fileReadable("'speakCommandDir$'/TTS_'.osName$'_play_command.txt")
562 createDirectory(sgc.scratchAudioDir$)
563 sgc.playCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_play_command.txt"
564 sgc.useAlternativePlayer = 1
568 ###############################################################
573 # initialiseSGC2.toneevaluation_table$ = ""
574 procedure initialize_toneevaluation_tables
576 if initialiseSGC2.toneevaluation_table$ != ""
577 select sgc2.performanceTable
580 initialiseSGC2.toneevaluation_table$ = ""
581 # Get the name of the table
582 call get_evaluation_table_labels 'config.language$'
583 performanceTableName$ = eval.performance$
585 if sgc.savePerf$ <> "" and fileReadable(sgc.savePerf$)
586 sgc2.performanceTable = Read Table from tab-separated file: sgc.savePerf$
587 Rename: performanceTableName$
588 # Check to make sure all columns are initialized, but only if Pinyin exists!
589 select sgc2.performanceTable
590 .column = Get column index: eval.pinyin$
592 select sgc2.performanceTable
594 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$'
596 .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$'"
597 while index_regex(.columnNameList$, "\S")
598 .columnNameList$ = replace_regex$(.columnNameList$, "^\s+", "", 1)
599 .columnHeader$ = extractWord$(.columnNameList$, "")
600 .columnNameList$ = replace_regex$(.columnNameList$, "^\s*'.columnHeader$'\s*", "", 1)
602 select sgc2.performanceTable
603 .column = Get column index: .columnHeader$
605 select sgc2.performanceTable
606 Append column: .columnHeader$
611 # Performance table has been read. Set the wordlist to the first row
612 select sgc2.performanceTable
613 wordlistName$ = Get value: 1, eval.wordlist$
614 call load_word_list: localWordlistDir$, 0
617 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$'
619 initialiseSGC2.toneevaluation_table$ = performanceTableName$
620 call get_toneevaluation_row 'eval.total$'
623 procedure get_toneevaluation_row .pinyin$
624 select sgc2.performanceTable
625 .row = Search column... "'eval.pinyin$'" '.pinyin$'
628 .row = Get number of rows
629 Set string value... '.row' "'eval.pinyin$'" '.pinyin$'
630 Set numeric value... '.row' 'eval.correct$' 0
631 Set numeric value... '.row' 'eval.wrong$' 0
632 Set numeric value... '.row' 'eval.total$' 0
633 Set numeric value... '.row' 'eval.high$' 0
634 Set numeric value... '.row' 'eval.low$' 0
635 Set numeric value... '.row' 'eval.wide$' 0
636 Set numeric value... '.row' 'eval.narrow$' 0
637 Set numeric value... '.row' 'eval.unknown$' 0
638 Set numeric value... '.row' 'eval.commented$' 0
639 Set numeric value... '.row' 'eval.level$' 0
640 Set numeric value... '.row' 'eval.time$' 0
641 Set string value... '.row' 'eval.wordlist$' 'wordlistName$'
642 Sort rows... 'eval.pinyin$'
643 .row = Search column... "'eval.pinyin$'" '.pinyin$'
647 procedure increment_toneevaluation_in_row .row .column$
648 select sgc2.performanceTable
649 .tmp = Get value... '.row' '.column$'
654 Set numeric value... '.row' '.column$' '.tmp'
657 Set string value: .row, eval.level$, config.strict$
659 # Set time stamp and wordlist
661 Set string value: .row, eval.time$, .dateTime$
662 Set string value: .row, eval.wordlist$, wordlistName$
666 # Update existing performance file with toneevaluation
667 procedure update_toneevaluation_file
668 if sgc.savePerf$ <> "" and fileReadable(sgc.savePerf$) and initialiseSGC2.toneevaluation_table$ <> ""
669 select sgc2.performanceTable
670 Write to table file... 'sgc.savePerf$'
674 procedure increment_toneevaluation_value .pinyin$ .column$
675 call get_toneevaluation_row '.pinyin$'
676 .row = get_toneevaluation_row.row
677 call increment_toneevaluation_in_row '.row' '.column$'
679 call get_toneevaluation_row 'eval.total$'
680 .row = get_toneevaluation_row.row
681 call increment_toneevaluation_in_row '.row' '.column$'
684 procedure add_feedback_to_toneevaluation .table$
685 select Table '.table$'
686 .line1$ = Get value... 1 Text
687 .line2$ = Get value... 2 Text
688 .label$ = Get value... 3 Text
690 .label$ = "'eval.unknown$'"
693 .tones$ = replace_regex$(left$(.line1$, rindex(.line1$, ":")), "[^0-9]", "", 0)
694 .recognized$ = replace_regex$(right$(.line1$, length(.line1$)-rindex(.line1$, ":")), "[^0-9]", "", 0)
697 call increment_toneevaluation_value 'sgc.pinyin$' 'eval.total$'
698 if .tones$ = .recognized$
699 call increment_toneevaluation_value 'sgc.pinyin$' 'eval.correct$'
702 call increment_toneevaluation_value 'sgc.pinyin$' 'eval.wrong$'
705 if index_regex(.label$, "(Correct|Wrong)") <= 0
706 if .label$ = "Correct"
707 .label$ = eval.correct$
709 .label$ = eval.wrong$
711 call increment_toneevaluation_value 'sgc.pinyin$' '.label$'
712 call increment_toneevaluation_value 'sgc.pinyin$' 'eval.commented$'
716 # Update performance table when SaveAudio is on
718 call update_toneevaluation_file
722 procedure setGrade .grade$
723 select sgc.currentWordlist
724 if recordedSound$ <> "" and sgc.pinyin$ <> ""
725 call get_toneevaluation_row 'sgc.pinyin$'
726 .row = get_toneevaluation_row.row
727 select sgc2.performanceTable
728 .col = Get column index... Grade
730 Insert column... 2 Grade
733 Set numeric value: .row, "Grade", '.grade$'
734 .numRows = Get number of rows
737 for .r from 2 to .numRows
738 .tmp = Get value: .r, "Grade"
746 .meanGrade = .sumGrade / .sumN
748 Set numeric value: 1, "Grade", .meanGrade
750 # Store current performance table
751 call update_toneevaluation_file
755 # Set mainPage.saveAudio$ to Grade
756 procedure set_grade_display .pinyin$
757 mainPage.saveAudio$ = ""
758 select sgc2.performanceTable
760 .col = Get column index: "Grade"
761 if .pinyin$ <> "" and .col > 0
762 call get_toneevaluation_row '.pinyin$'
763 .row = get_toneevaluation_row.row
765 .grade$ = Get value: .row, "Grade"
766 if index_regex(.grade$, "[0-9]") <= 0
772 mainPage.saveAudio$ = .grade$
776 ###############################################################
778 # Miscelaneous procedures
780 ###############################################################
783 procedure synthesize_sound .pinyin$
785 if speakCommandFile$ <> "" and fileReadable(speakCommandFile$)
786 .command$ < 'speakCommandFile$'
787 .command$ = replace$(.command$, "'newline$'", " ", 0)
789 system_nocheck PATH=${PATH}:/usr/local/bin:/opt/local/bin; bash -rc -- ''.command$' "'.pinyin$'"'
791 system_nocheck bash -rc -- ''.command$' "'.pinyin$'"'
793 system_nocheck call '.command$' "'.pinyin$'"
795 elsif sgc.nativeTTScommand$ <> "" and config.voice <= 0
796 .text$ = replace_regex$(.pinyin$, "0$", "''", 0)
797 system_nocheck 'sgc.nativeTTScommand$' "'.text$'"
798 elsif sgc2.synthesizer > 0
799 select sgc2.synthesizer
800 Play text... '.pinyin$'
804 procedure align_recordedSound .pinyin$
805 if 0 and sgc2.synthesizer > 0 and recordedSound$ <> ""
806 select Sound 'recordedSound$'
807 .recordedTextGrid = To TextGrid... pinyin
808 Set interval text... 1 1 '.pinyin$'
809 select sgc2.synthesizer
810 plus Sound 'recordedSound$'
811 plus .recordedTextGrid
812 sgc.alignedTextGrid = nowarn noprogress To TextGrid (align,trim)... 1 1 1 -35 0.1 0.1 0.08
813 Rename... AlignedTextGrid
814 select .recordedTextGrid