Better detection tone combinations
[sgc2.git] / InitialiseSGC2.praat
bloba48a428e385d57013bc4a21573cf8023cd7e2ceb
2 # SpeakGoodChinese 2.0
3
4 # Intializing Praat script
6 #     SpeakGoodChinese: InitializeSGC2.praat defines and sets the global variables
7 #     and loads general SGC2 code 
8 #     
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
13
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.
18
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.
23
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
27
29 # Do not store these variables as preferences
30 sgc.nonPreferences$ = " config.savePerf config.openPerf config.clearSummary config.audioName "
32 # Information for logging
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$ = ""
40 # Define canvas
41 viewportMargin = 5
42 yWordlist = 11
43 yFeedback = yWordlist + 5
44 yPinyin = yFeedback + 10
45 yContour = yPinyin + 15
46 wipeContourArea$ = "demo Paint rectangle... White 20 80 'yContour' 100"
47 wipePinyinArea$ = "demo Paint rectangle... White 20 80 'yPinyin' 'yContour'"
48 wipeFeedbackArea$ = "demo Paint rectangle... White 0 100 'yFeedback' 'yPinyin'"
49 wipeWordlistArea$ = "demo Paint rectangle... White 20 80 'yWordlist' 'yFeedback'"
51 # Pop-Up window colors
52 sgc2.popUp_bordercolor$ = "{0.5,0.5,1}"
53 sgc2.popUp_backgroundcolor$ = "{0.9,0.9,1}"
55 # Initialize parameters
56 alertText$ = ""
57 te.currentWord = 1
58 te.numberOfWords = 0
59 te.recordedSound = 0
60 sgc.saveAudioOn = 0
61 sgc.writeAll = 0
62 pinyin$ = ""
63 sgc.pinyin$ = ""
64 character$ = ""
65 buttons$ = ""
66 config$ = ""
67 wordlistNum = 1
68 wordlistName$ = ""
69 wordlist$ = ""
70 mainPage.play = -1
71 config.deleteWordlist = -1
72 config.displayNumbers = 1
73 config.displayPinyin = 1
74 config.displayChar = 0
75 config.displayTrans = 1
76 config.useSoundExample = 1
77 config.synthesis$ = "_DISABLED_"
78 config.input$ = "Microphone"
79 config.showBackground = 1
80 sgc2.noiseThresshold = -30
81 config.strict$ = "1"
82 sgc.highestLevel = 3
83 config.savePerf = 0
84 config.openPerf = 0
85 config.clearSummary = 0
86 config.audioName$ = ""
87 sgc.savePerf$ = ""
88 sgc.saveAudio$ = ""
89 mainPage.saveAudio$ = ""
91 sgc_ToneProt.minimumPitch = 40
92 sgc_ToneProt.maximumPitch = 600
94 # Platform dependent settings
95 if macintosh or windows
96         config.displayChar = 1
97         config.displayNumbers = 0
98 endif
99 if windows and endsWith(build_SHA$, " XP")
100         config.displayChar = 0
101         config.displayNumbers = 0
102 endif
103 if unix
104         config.displayChar = 0
105         config.displayNumbers = 1
106 endif
108 if unix
109         samplingFrequency = 44100
110 elsif macintosh
111         samplingFrequency = 44100
112 elsif windows
113         samplingFrequency = 44100
114 endif
115 recordingTime = 2
117 logging = 0
118 config.language$ = "EN"
119 config.register = 249
120 preferencesAppFile$ = preferencesAppDir$+"/sgc2rc.txt"
121 preferencesLogDir$ = "'preferencesAppDir$'/log"
122 preferencesTableDir$ = "'preferencesAppDir$'/Data"
123 sgc2wordlists$ = "'preferencesAppDir$'/wordlists"
124 localWordlistDir$ = sgc2wordlists$
126 # Global word lists must be installed BY THE ADMINISTRATOR
127 # This means, create the directory 'globalwordlists$' and
128 # fill it with wordlist directories containing wordlist.Table
129 # and audio files. They can be copied from a local directory.
130 globalwordlists$ = ""
131 globaltablelists$ = ""
132 globalTTSdir$ = ""
133 if unix
134         globalwordlists$ = "/etc/'sgc2.demoAppName$'/wordlists"
135         globaltablelists$ = "/etc/'sgc2.demoAppName$'/Data"     
136         globalTTSdir$ = "/etc/'sgc2.demoAppName$'/TTS"  
137 elsif macintosh
138         globalwordlists$ = "/Library/Preferences/'sgc2.demoAppName$'/wordlists"
139         globaltablelists$ = "/Library/Preferences/'sgc2.demoAppName$'/Data"
140         globalTTSdir$ = "/Library/Preferences/'sgc2.demoAppName$'/TTS"  
141 elsif windows
142         globalwordlists$ = "C:/Documents and Settings/All Users/Application Data/'sgc2.demoAppName$'/wordlists"
143         globaltablelists$ = "C:/Documents and Settings/All Users/Application Data/'sgc2.demoAppName$'/Data"
144         globalTTSdir$ = "C:/Documents and Settings/All Users/Application Data/'sgc2.demoAppName$'/TTS"
145 endif
146 sgc2.synthesizer = -1
147 # Define a Praat TTS command that will set sgc2.synthesizer
148 sgc2.normalTTScommand$ = "call create_default_TTS Mandarin f4 10000 0.01 50 100 95 no IPA"
149 sgc2.advancedTTScommand$ = "call create_default_TTS Mandarin f4 10000 0.01 50 70 125 no IPA"
150 sgc2.alignedTextGrid = -1
152 ##############################################################
154 config.shuffleLists = 1
155 defaultFontSize = 12
156 defaultFont$ = "Helvetica"
157 defaultLineWidth = 1
159 # Set up directories if they do not exist already
160 call set_up_directories
162 # Get saved preferences
163 call read_preferences ""
165 # Set up TTS system
166 speakCommandDir$ = "'preferencesAppDir$'/TTS"
167 speakCommandFile$ = ""
168 call set_up_TTS
170 # Set inital language
171 call set_language 'config.language$'
173 # Get the word-list
174 call load_word_list "'localWordlistDir$'" 0
176 # Set up evaluation table
177 initialiseSGC2.toneevaluation_table$ = ""
178 call initialize_toneevaluation_tables
180 # Draw inital window
181 call init_window
183 ###############################################################
185 # Obligatory procedures
187 ###############################################################
188 # Initialize Demo Window
189 procedure init_window
190     demo Erase all
191         demo Line width... 'defaultLineWidth'
192         demo 'defaultFont$'
193         call set_font_size 'defaultFontSize'
194         demo Black
195         
196         # If there is no recorded sound, try to read stored recording
197         if recordedSound$ = "" and sgc.saveAudio$ <> ""
198                 sgc.pinyin$ = ""
199                 select Table 'wordlist$'
200                 if te.currentWord > 0 and te.currentWord <= te.numberOfWords
201                         sgc.pinyin$ = Get value... 'te.currentWord' Pinyin
202                         .outputName$ = "'sgc.saveAudio$'/'sgc.pinyin$'.wav"
203                         if fileReadable(.outputName$)
204                                 te.recordedSound = Read from file: .outputName$
205                                 recordedSound$ = selected$("Sound")
206                                 call recognizeTone
207                                 
208                                 # Set config.audioName
209                                 .tmp$ = replace_regex$(sgc.saveAudio$, "[^/\\]+[/\\]?$", "", 0)
210                                 config.audioName$ = replace$(sgc.saveAudio$, .tmp$, "", 0)
211                                 
212                         endif
213                 endif
214         endif
215         
216         # Set mainPage.saveAudio$ grade
217         call set_grade_display 'sgc.pinyin$'
218         
219         # Update screen
220         call reset_viewport
221         .windowTitle$ = replace$(wordlistName$, "_", " ", 0)
222         call set_window_title 'buttons$' '.windowTitle$'
223         # Display the word-list
224         call write_word_list
225     # Wipe screen and draw background
226     call wipeArea 'wipeContourArea$'
227         if config.showBackground
228                 call draw_background Background
229         endif
230     # Define buttons in a table
231     call init_buttons
232     # Set Play button
233         call Set_Play_Button
234     
235         # Draw the contour
236         call draw_tone_contour
237         # SaveAudio light
238         call paint_saveAudio_light
239         # Set play button
240         
241 endproc
243 # Make sure all Preferences directories are available
244 procedure set_up_directories
245         .dirPath$ = "'preferencesAppDir$'"
246         createDirectory(.dirPath$)
247         .dirPath$ > '.dirPath$'/directory.txt
248         createDirectory("'.dirPath$'/wordlists")
249         .dirPath$ > '.dirPath$'/wordlists/directory.txt
250         createDirectory("'.dirPath$'/pitchmodels")
251         .dirPath$ > '.dirPath$'/pitchmodels/directory.txt
252         createDirectory("'.dirPath$'/log")
253         .dirPath$ > '.dirPath$'/log/directory.txt
254         createDirectory("'.dirPath$'/TTS")
255         .dirPath$ > '.dirPath$'/TTS/directory.txt
256 endproc
259 # Retrieve and store setting between sessions
261 procedure read_preferences .preferencesFile$
262         if not fileReadable(.preferencesFile$)
263                 .preferencesFile$ = preferencesAppFile$
264         endif
265         if fileReadable(.preferencesFile$)
266                 Read from file... 'preferencesAppFile$'
267                 .preferenceTable$ = selected$("Table")
268                 .numPrefKeys = Get number of rows
269                 for .row to .numPrefKeys
270                         .variableName$ = Get value... '.row' Key
271                         if variableExists(.variableName$)
272                                 .variableValue = Get value... '.row' Value
273                                 if .variableValue <> undefined
274                                         '.variableName$' = '.variableValue'
275                                 endif
276                         elsif variableExists(.variableName$+"$")
277                                 .variableValue$ = Get value... '.row' Value
278                                 .variableName$ = .variableName$+"$"
279                                 '.variableName$' = "'.variableValue$'"
280                         endif
281                 endfor
282                 
283                 select Table '.preferenceTable$'
284                 Remove
285         endif
286 endproc
288 procedure write_preferences .preferencesFile$
289         Create Table with column names... Preferences 0 Key Value
290         if index_regex(.preferencesFile$, "[a-zA-Z0-9]") <= 0
291                 .preferencesFile$ = preferencesAppFile$
292         endif
293         .row = 0
294         
295         for .tableNum from 1 to 2
296                 if .tableNum = 1
297                         .table$ = "Config"
298                 elsif .tableNum = 2
299                         .table$ = "MainPage"
300                 endif
301                 .varPrefix$ = replace_regex$(.table$, "^(.)", "\l\1", 0)
303                 select Table '.table$'
304                 .numTableRows = Get number of rows
305                 for .tablerow to .numTableRows
306                         select Table '.table$'
307                         .label$ = Get value... '.tablerow' Label
308                         .variableName$ = .varPrefix$+"."+(replace_regex$(.label$, "^(.)", "\l\1", 0))
309                         .keyName$ = .variableName$
310                         .value$ = ""
311                         if sgc.nonPreferences$ <> "" and index(sgc.nonPreferences$, " '.variableName$' ")
312                                 .value$ = ""
313                         elsif variableExists(.variableName$)
314                                 .value = '.variableName$'
315                                 .value$ = "'.value'"
316                         elsif variableExists(.variableName$ + "$")
317                                 .variableName$ = .variableName$ + "$"
318                                 .value$ = '.variableName$'
319                         elsif index(.variableName$, "_") > 0
320                                 .variableName$ = left$(.variableName$, rindex(.variableName$, "_") - 1) 
321                                 .keyName$ = .variableName$
322                                 select Table Preferences
323                                 .prefRow = Search column... Key '.keyName$'
324                                 if .prefRow <= 0
325                                         if variableExists(.variableName$)
326                                            .value = '.variableName$'
327                                            .value$ = "'.value'"
328                                         elsif variableExists(.variableName$ + "$")
329                                            .variableName$ = .variableName$ + "$"
330                                            .value$ = '.variableName$'
331                                         endif
332                                 endif
333                         endif
335                         if .value$ <> ""
336                                 select Table Preferences
337                                 Append row
338                                 .row += 1
339                                 Set string value... '.row' Key '.keyName$'
340                                 Set string value... '.row' Value '.value$'
341                         endif
342                 endfor
343         endfor
344         
345         # Some extra settings
346         select Table Preferences
347         Append row
348         .row += 1
349         Set string value... '.row' Key wordlistDir
350         Set string value... '.row' Value 'localWordlistDir$'
352         select Table Preferences
353         Append row
354         .row += 1
355         Set string value... '.row' Key wordlistName
356         Set string value... '.row' Value 'wordlistName$'
358         select Table Preferences
359         Write to table file... '.preferencesFile$'
360         Remove
362 endproc
364 ###############################################################
366 # TTS (speech synthesis). Place commands in user info
368 # Prerequisites
369 # speakCommandDir$ = "'preferencesAppDir$'/TTS"
370 # speakCommandFile$ = ""
372 # Make sure sgc2.synthesizer is set!
373 procedure create_default_TTS .language$ .voice$ .samplefreq .gap .pitch_adj .pitch_range .words_per_minute .use_data$ .espeak_phones$
374         sgc2.synthesizer = Create SpeechSynthesizer... '.language$' '.voice$'
375         Set speech output settings... .samplefreq .gap .pitch_adj .pitch_range .words_per_minute '.use_data$' '.espeak_phones$'
376 endproc
378 procedure set_up_TTS
379         if sgc2.synthesizer > 0
380                 select sgc2.synthesizer
381                 Remove
382                 sgc2.synthesizer = -1
383         endif
384         # Note, the TTScommand must set sgc2.synthesizer!
385         if config.strict$ = "'sgc.highestLevel'"
386                 'sgc2.advancedTTScommand$'
387         else
388                 'sgc2.normalTTScommand$'
389         endif
391         if macintosh
392                 .ttscommand$ = "speak"
393                 .osName$ = "OSX"
394                 .quote$ = ""
395         elsif unix
396                 .ttscommand$ = "espeak"
397                 .osName$ = "UNIX"
398                 .quote$ = ""
399         elsif windows
400                 .ttscommand$ = "C:/Program Files/eSpeak/command_line/espeak.exe"
401                 .osName$ = "WIN"
402                 .quote$ = """"
403         endif
404         # Global TTS command has precedence
405         if fileReadable("'globalTTSdir$'/TTS_'.osName$'_command.txt")
406                 speakCommandFile$ = "'globalTTSdir$'/TTS_'.osName$'_command.txt"
407                 if config.synthesis$ = "_DISABLED_"
408                         # Default is ON
409                         config.synthesis$ = "eSpeak"
410                 endif
411         endif
413         # Local TTS command, if there is no global one
414         # Command does not exist yet, create it if eSpeak is installed
415         # Make sure to quote the path!
416         if speakCommandFile$ = ""
417                 # Autodetect synthesizer command
418 #               if not fileReadable("'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt")
419 #                       .command_path$ = ""
420 #                       if macintosh
421 #                               system_nocheck  PATH=${PATH}:/opt/local/bin; bash -c -- 'which '.ttscommand$' > "'speakCommandDir$'/command_path.txt"'
422 #                               .command_path$ < 'speakCommandDir$'/command_path.txt
423 #                       elsif unix
424 #                               system_nocheck  PATH=${PATH};bash -c -- 'which '.ttscommand$' > "'speakCommandDir$'/command_path.txt"'
425 #                               .command_path$ < 'speakCommandDir$'/command_path.txt
426 #                       elsif windows
427 #                               if fileReadable(.ttscommand$)
428 #                                       .command_path$ = .ttscommand$
429 #                               endif
430 #                       endif
431 #                       # Remove any newlines
432 #                       .command_path$ = replace$(.command_path$, "'newline$'", "", 0)
434 #                       # Command path found
435 #                       if sgc2.synthesizer <= 0 and .command_path$ <> "" and fileReadable(.command_path$)
436 #                               deleteFile("'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt")
437 #                               fileappend "'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt"  
438 #                               ...'.quote$''.ttscommand$''.quote$' -v zh+f4 -s 100 'newline$'
439 #                               speakCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt"
440 #                       endif
441 #               endif
442 #               if fileReadable("'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt")
443                         speakCommandFile$ = "'speakCommandDir$'/TTS_'.osName$'_eSpeak_command.txt"
444                 endif
445                 deleteFile("'speakCommandDir$'/command_path.txt")
446         endif
447         
448         # Close off (other TTS maybe a later option)
449         if sgc2.synthesizer > 0 or (speakCommandFile$ <> "" and fileReadable(speakCommandFile$))
450                 config.synthesis$ = "eSpeak"
451         endif
452 endproc
454 ###############################################################
456 # Evaluation tables
458 # Prerequisites
459 # initialiseSGC2.toneevaluation_table$ = ""
460 procedure initialize_toneevaluation_tables
461         # Remove old table
462         if initialiseSGC2.toneevaluation_table$ != ""
463                 select Table 'initialiseSGC2.toneevaluation_table$'
464                 Remove
465         endif
466         initialiseSGC2.toneevaluation_table$ = ""
467         
468         if sgc.savePerf$ <> "" and fileReadable(sgc.savePerf$)
469                 sgc2.performanceTable = Read Table from tab-separated file: sgc.savePerf$
470                 Rename: "Performance"
471         else
472                 # Create new table
473                 sgc2.performanceTable = Create Table with column names... Performance 0 Pinyin Correct Wrong Total High Low Wide Narrow Unknown Commented Time
474         endif
475         initialiseSGC2.toneevaluation_table$ = "Performance"
476         call get_toneevaluation_row Total
477 endproc
479 procedure get_toneevaluation_row .pinyin$
480         select Table 'initialiseSGC2.toneevaluation_table$'
481     .row = Search column... Pinyin '.pinyin$'
482         if .row < 1
483                 Append row
484                 .row = Get number of rows
485                 Set string value... '.row' Pinyin '.pinyin$'
486                 Set numeric value... '.row' Correct 0
487                 Set numeric value... '.row' Wrong 0
488                 Set numeric value... '.row' Total 0
489                 Set numeric value... '.row' High 0
490                 Set numeric value... '.row' Low 0
491                 Set numeric value... '.row' Wide 0
492                 Set numeric value... '.row' Narrow 0
493                 Set numeric value... '.row' Unknown 0
494                 Set numeric value... '.row' Commented 0
495                 Set numeric value... '.row' Time 0
496                 Sort rows... Pinyin
497         .row = Search column... Pinyin '.pinyin$'
498         endif
499 endproc
501 procedure increment_toneevaluation_in_row .row .column$
502         select Table 'initialiseSGC2.toneevaluation_table$'
503         .tmp = Get value... '.row' '.column$'
504         .tmp += 1
505         Set numeric value... '.row' '.column$' '.tmp'
506         
507         # Set time stamp
508         .dateTime$ = date$()
509         Set string value: .row, "Time", .dateTime$
510         
511 endproc
513 # Update existing performance file with toneevaluation
514 procedure update_toneevaluation_file
515         if sgc.savePerf$ <> "" and fileReadable(sgc.savePerf$) and initialiseSGC2.toneevaluation_table$ <> ""
516                 select Table 'initialiseSGC2.toneevaluation_table$'
517                 Write to table file... 'sgc.savePerf$'
518         endif
519 endproc
521 procedure increment_toneevaluation_value .pinyin$ .column$
522         call get_toneevaluation_row '.pinyin$'
523         .row = get_toneevaluation_row.row
524         call increment_toneevaluation_in_row '.row' '.column$'
525         
526         call get_toneevaluation_row Total
527         .row = get_toneevaluation_row.row
528         call increment_toneevaluation_in_row '.row' '.column$'
529 endproc
531 procedure add_feedback_to_toneevaluation .table$
532     select Table '.table$'
533     .line1$ = Get value... 1 Text
534     .line2$ = Get value... 2 Text
535     .label$ = Get value... 3 Text
536         if .label$ = "6"
537                 .label$ = "Unknown"
538         endif
539         
540         .tones$ = replace_regex$(left$(.line1$, rindex(.line1$, ":")), "[^0-9]", "", 0)
541         .recognized$ = replace_regex$(right$(.line1$, length(.line1$)-rindex(.line1$, ":")), "[^0-9]", "", 0)
542         
543         # Set evaluation
544         call increment_toneevaluation_value 'sgc.pinyin$' Total
545         if .tones$ = .recognized$
546                 call increment_toneevaluation_value 'sgc.pinyin$' Correct
547         else
548                 call increment_toneevaluation_value 'sgc.pinyin$' Wrong
549         endif
550         if index_regex(.label$, "(Correct|Wrong)") <= 0
551                 call increment_toneevaluation_value 'sgc.pinyin$' '.label$'
552                 call increment_toneevaluation_value 'sgc.pinyin$' Commented
553         endif
554         
555         # Update performance table when SaveAudio is on
556         if sgc.saveAudioOn
557                 call update_toneevaluation_file
558         endif
559 endproc
561 procedure setGrade .grade$
562         select Table 'wordlist$'
563         if recordedSound$ <> "" and sgc.pinyin$ <> ""           
564                 call get_toneevaluation_row 'sgc.pinyin$'
565                 .row = get_toneevaluation_row.row
566                 select Table 'initialiseSGC2.toneevaluation_table$'
567                 .col = Get column index... Grade
568                 if .col <= 0
569                         Insert column... 2 Grade
570                 endif
571                         
572                 Set numeric value: .row, "Grade", '.grade$'
573                 .numRows = Get number of rows
574                 .sumGrade = 0
575                 .sumN = 0
576                 for .r from 2 to .numRows
577                         .tmp = Get value: .r, "Grade"
578                         if .tmp <> undefined
579                                 .sumGrade += .tmp
580                                 .sumN += 1
581                         endif
582                 endfor
583                 .meanGrade = -1
584                 if .sumN > 0
585                         .meanGrade = .sumGrade / .sumN
586                 endif
587                 Set numeric value: 1, "Grade", .meanGrade
588                 
589                 # Store current performance table
590                 call update_toneevaluation_file
591         endif
592 endproc
594 # Set mainPage.saveAudio$ to Grade
595 procedure set_grade_display .pinyin$
596         mainPage.saveAudio$ = ""
597         select Table 'initialiseSGC2.toneevaluation_table$'
598         .grade$ = ""
599         .col = Get column index: "Grade"
600         if .pinyin$ <> "" and .col > 0
601                 call get_toneevaluation_row '.pinyin$'
602                 .row = get_toneevaluation_row.row
603                 if .row > 0
604                         .grade$ = Get value: .row, "Grade"
605                         if index_regex(.grade$, "[0-9]") <= 0
606                                 .grade$ = ""
607                         endif
608                 endif
609         endif
610         if .grade$ <> ""
611                 mainPage.saveAudio$ = .grade$
612         endif
613 endproc
614         
615 ###############################################################
617 # Miscelaneous procedures
619 ###############################################################
621 # TTS synthesis
622 procedure synthesize_sound .pinyin$
623         .command$ = ""
624         if speakCommandFile$ <> "" and fileReadable(speakCommandFile$)
625                 .command$ < 'speakCommandFile$'
626                 .command$ = replace$(.command$, "'newline$'", " ", 0)
627                 if macintosh
628                         system_nocheck PATH=${PATH}:/usr/local/bin:/opt/local/bin; bash -rc -- ''.command$' "'.pinyin$'"'
629                 elsif unix
630                         system_nocheck bash -rc -- ''.command$' "'.pinyin$'"'
631                 elsif windows
632                         system_nocheck call '.command$' "'.pinyin$'"'
633                 endif
634         elsif sgc2.synthesizer > 0
635                 select sgc2.synthesizer
636                 Play text... '.pinyin$'
637         endif
638 endproc
640 procedure align_recordedSound .pinyin$
641         if 0 and sgc2.synthesizer > 0 and recordedSound$ <> ""
642                 select Sound 'recordedSound$'
643                 .recordedTextGrid = To TextGrid... pinyin
644                 Set interval text... 1 1 '.pinyin$'
645                 select sgc2.synthesizer
646                 plus Sound 'recordedSound$'
647                 plus .recordedTextGrid
648                 sgc2.alignedTextGrid = nowarn noprogress To TextGrid (align,trim)... 1 1 1 -35 0.1 0.1 0.08
649                 Rename... AlignedTextGrid
650                 select .recordedTextGrid
651                 Remove
652         endif
653 endproc