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