From 8b33c771ddf510e0e8ae7af76d5014d64d0d8b8c Mon Sep 17 00:00:00 2001 From: Rob van Son Date: Fri, 31 Jan 2014 12:16:45 +0100 Subject: [PATCH] Refactored drawing routines and changed pitch extracting settings --- Config.praat | 2 ++ Data/Background.Table | 6 +++--- InitialiseSGC2.praat | 13 ++++++++----- MainPage.praat | 25 ++++++++++++++++++------- ToneProt/DrawToneContour.praat | 16 ++++++++++++++++ ToneProt/SGC_ToneProt.praat | 31 +++++++------------------------ ToneProt/ToneScript.praat | 4 ++-- sgc2.praat | 34 +++++++++++++++++++++++++++++----- 8 files changed, 85 insertions(+), 46 deletions(-) diff --git a/Config.praat b/Config.praat index e7d2259..83b74d5 100644 --- a/Config.praat +++ b/Config.praat @@ -473,6 +473,8 @@ endproc # Word lists: It is a VERY good idea to make sure that word-lists # have unique names. procedure load_word_list .localdir$ .relnumber + call clean_up_sound + # Remove old word list if wordlist$ <> "" select Table 'wordlist$' diff --git a/Data/Background.Table b/Data/Background.Table index e504302..b5e9e0e 100644 --- a/Data/Background.Table +++ b/Data/Background.Table @@ -1,8 +1,8 @@ font size align colour text Helvetica 36 centre {1,1,1} -Helvetica 36 centre {0.99,0.97,0.85} SPEAK GOOD CHINESE 2.0 -Helvetica 36 centre {0.99,0.97,0.85} shuō​ hǎo​ Zhōng​wén​ -Helvetica 36 centre {0.99,0.97,0.85} 说好中文 +Helvetica 36 centre {0.95,0.93,0.80} SPEAK GOOD CHINESE 2.0 +Helvetica 36 centre {0.95,0.93,0.80} shuō​ hǎo​ Zhōng​wén​ +Helvetica 36 centre {0.95,0.93,0.80} 说好中文 Helvetica 36 centre {1,1,1} Helvetica 36 centre {1,1,1} diff --git a/InitialiseSGC2.praat b/InitialiseSGC2.praat index 1a5d4e0..ee01533 100644 --- a/InitialiseSGC2.praat +++ b/InitialiseSGC2.praat @@ -51,6 +51,7 @@ sgc2.popUp_backgroundcolor$ = "{0.9,0.9,1}" alertText$ = "" te.currentWord = 1 te.numberOfWords = 0 +te.recordedSound = 0 pinyin$ = "" character$ = "" buttons$ = "" @@ -170,20 +171,22 @@ call init_window # Initialize Demo Window procedure init_window demo Erase all - if config.showBackground - call draw_background Background - endif demo Line width... 'defaultLineWidth' demo 'defaultFont$' call set_font_size 'defaultFontSize' demo Black call reset_viewport - # Define buttons in a table - call init_buttons .windowTitle$ = replace$(wordlistName$, "_", " ", 0) call set_window_title 'buttons$' '.windowTitle$' # Display the word-list call write_word_list + # Wipe screen and draw background + call wipeArea 'wipeContourArea$' + if config.showBackground + call draw_background Background + endif + # Define buttons in a table + call init_buttons # Draw the contour call draw_tone_contour # Logging light diff --git a/MainPage.praat b/MainPage.praat index 1a08e4f..1174596 100644 --- a/MainPage.praat +++ b/MainPage.praat @@ -176,6 +176,7 @@ procedure processMainPageExample .clickX .clickY .pressed$ endproc procedure processMainPagePrevious .clickX .clickY .pressed$ + call clean_up_sound call display_text Grey te.currentWord -= 1 call init_window @@ -185,6 +186,7 @@ procedure processMainPagePrevious .clickX .clickY .pressed$ endproc procedure processMainPageNext .clickX .clickY .pressed$ + call clean_up_sound call display_text Grey te.currentWord += 1 call init_window @@ -238,6 +240,11 @@ endproc procedure processMainPageRecord .clickX .clickY .pressed$ call record_sound call recognizeTone + + # Wipe screen + call wipeArea 'wipeContourArea$' + + call draw_tone_contour # Write text (again) call display_word_list_name call display_text Black @@ -299,19 +306,18 @@ endproc # Draw a tone contour procedure draw_tone_contour - # Wipe screen - call reset_viewport - call wipeArea 'wipeContourArea$' - if config.showBackground - call draw_background Background - endif select Table 'wordlist$' if te.currentWord > 0 and te.currentWord <= te.numberOfWords .sound$ = Get value... 'te.currentWord' Sound .pinyin$ = Get value... 'te.currentWord' Pinyin call drawToneContour '.pinyin$' 'config.register' call reset_viewport - endif + + if te.recordedPitch > 0 + call drawSourceToneContour te.recordedPitch + endif + endif + endproc procedure recognizeTone @@ -321,6 +327,9 @@ procedure recognizeTone .pinyin$ = Get value... 'te.currentWord' Pinyin call align_recordedSound '.pinyin$' call sgc_ToneProt 'recordedSound$' '.pinyin$' 'config.register' 'config.strict' 'config.language$' + # sgc_ToneProt manipulates the sound given. Reconnect + select Sound 'recordedSound$' + te.recordedSound = selected("Sound") call reset_viewport endif endproc @@ -371,6 +380,7 @@ endproc procedure display_text .color$ select Table 'wordlist$' if te.currentWord < 0 or te.currentWord > te.numberOfWords+1 + call clean_up_sound if config.shuffleLists Randomize rows endif @@ -402,6 +412,7 @@ procedure display_text .color$ .displayText$ = .displayText$ + " \s{%%"+ .displayTrans$ + "%}" endif elsif te.currentWord = 0 or te.currentWord = te.numberOfWords+1 + call clean_up_sound .displayText$ = "---" endif diff --git a/ToneProt/DrawToneContour.praat b/ToneProt/DrawToneContour.praat index a007ea3..dce1458 100644 --- a/ToneProt/DrawToneContour.praat +++ b/ToneProt/DrawToneContour.praat @@ -38,3 +38,19 @@ procedure drawToneContour drawToneContour.pinyin$ drawToneContour.register Remove endproc + +procedure drawSourceToneContour drawToneContour.sourcePitch + if drawToneContour.sourcePitch > 0 + call reset_viewport + demo Select inner viewport... 20 80 40 100 + demo Axes... 0 100 0 100 + + select drawToneContour.sourcePitch + demo Red + demo Line width... 3 + demo Draw... 0 0 0 'freqTop' 0 + + demo Line width... 1 + call reset_viewport + endif +endproc diff --git a/ToneProt/SGC_ToneProt.praat b/ToneProt/SGC_ToneProt.praat index 777d15c..97584e1 100644 --- a/ToneProt/SGC_ToneProt.praat +++ b/ToneProt/SGC_ToneProt.praat @@ -107,7 +107,7 @@ procedure sgc_ToneProt sgc_ToneProt.currentSound$ sgc_ToneProt.pinyin$ sgc_ToneP select Sound Source durationSource = Get total duration call convert2Pitch 'sgc_ToneProt.minimumPitch' 'sgc_ToneProt.maximumPitch' - .sourcePitch = convert2Pitch.object + te.recordedPitch = convert2Pitch.object Rename... SourcePitch # It is rather dangerous to kill Octave errors, so be careful @@ -115,19 +115,20 @@ procedure sgc_ToneProt sgc_ToneProt.currentSound$ sgc_ToneProt.pinyin$ sgc_ToneP Rename... OldSource Kill octave jumps Rename... SourcePitch + te.recordedPitch = selected("Pitch") select Pitch OldSource Remove endif # Remove all pitch points outside a band around the upper sgc_ToneProt.register - select Pitch SourcePitch + select te.recordedPitch upperCutOff = 1.7*sgc_ToneProt.upperRegisterInput lowerCutOff = sgc_ToneProt.upperRegisterInput/4 Formula... if self > 'upperCutOff' then -1 else self endif Formula... if self < 'lowerCutOff' then -1 else self endif # Get range and top - select Pitch SourcePitch + select te.recordedPitch maximumRecFzero = Get quantile... 0 0 0.95 Hertz timeMaximum = Get time of maximum... 0 0 Hertz Parabolic minimumRecFzero = Get quantile... 0 0 0.05 Hertz @@ -187,7 +188,7 @@ procedure sgc_ToneProt sgc_ToneProt.currentSound$ sgc_ToneProt.pinyin$ sgc_ToneP sgc_ToneProt.newUpperRegister = round(sgc_ToneProt.newUpperRegister) # Remove all pitch points outside a band around the upper sgc_ToneProt.register - select Pitch SourcePitch + select te.recordedPitch upperCutOff = 1.5*sgc_ToneProt.newUpperRegister lowerCutOff = sgc_ToneProt.newUpperRegister/3 Formula... if self > 'upperCutOff' then -1 else self endif @@ -197,12 +198,13 @@ procedure sgc_ToneProt sgc_ToneProt.currentSound$ sgc_ToneProt.pinyin$ sgc_ToneP Rename... OldSourcePitch Kill octave jumps Rename... SourcePitch + te.recordedPitch = selected("Pitch") select Pitch OldSourcePitch Remove endif # It is good to have the lowest and highest pitch frequencies - select Pitch SourcePitch + select te.recordedPitch timeMaximum = Get time of maximum... 0 0 Hertz Parabolic timeMinimum = Get time of minimum... 0 0 Hertz Parabolic @@ -449,24 +451,6 @@ procedure sgc_ToneProt sgc_ToneProt.currentSound$ sgc_ToneProt.pinyin$ sgc_ToneP # Show pitch tracks freqTop = 1.5 * sgc_ToneProt.upperRegisterInput - call reset_viewport - demo Paint rectangle... White 15 85 40 105 - demo Select inner viewport... 20 80 40 100 - demo Axes... 0 100 0 100 - - select Pitch SourcePitch - demo Red - demo Line width... 3 - demo Draw... 0 0 0 'freqTop' 0 - - select Pitch 'sgc_ToneProt.currentTestWord$' - demo Green - demo Draw... 0 0 0 'freqTop' 0 - - demo Line width... 1 - demo 12 - - call reset_viewport # Replace recorded sound with new sound if not fileReadable(sgc_ToneProt.currentSound$) @@ -479,7 +463,6 @@ procedure sgc_ToneProt sgc_ToneProt.currentSound$ sgc_ToneProt.pinyin$ sgc_ToneP # Clean up select Sound Source - plus Pitch SourcePitch plus Pitch 'sgc_ToneProt.currentTestWord$' Remove endproc diff --git a/ToneProt/ToneScript.praat b/ToneProt/ToneScript.praat index 83f35b9..d467e85 100644 --- a/ToneProt/ToneScript.praat +++ b/ToneProt/ToneScript.praat @@ -340,6 +340,6 @@ procedure generateWord toneScript.whatToGenerate$ toneScript.theWord$ toneScript endproc procedure convert2Pitch .minimumPitch .maximumPitch - .object = noprogress To Pitch (ac)... 0 '.minimumPitch' 25 yes 0.05 0.3 0.01 0.6 0.14 '.maximumPitch' - #.object = noprogress To Pitch (cc)... 0 '.minimumPitch' 25 yes 0.05 0.3 0.01 0.6 0.14 '.maximumPitch' + #.object = noprogress To Pitch (ac)... 0 '.minimumPitch' 25 yes 0.05 0.3 0.01 0.6 0.14 '.maximumPitch' + .object = noprogress To Pitch (cc)... 0 '.minimumPitch' 15 yes 0.03 0.50 0.045 0.35 0.14 '.maximumPitch' endproc diff --git a/sgc2.praat b/sgc2.praat index a62377c..f1c1bbb 100644 --- a/sgc2.praat +++ b/sgc2.praat @@ -40,6 +40,8 @@ configTableName$ = "Config" buttons$ = "" config$ = "" recordedSound$ = "" +te.recordedSound = 0 +te.recordedPitch = 0 samplingFrequency = 44100 recordingTime = 4 @@ -698,11 +700,7 @@ procedure play_sound .sound$ endproc procedure record_sound - if recordedSound$ != "" - select Sound 'recordedSound$' - Remove - recordedSound$ = "" - endif + call clean_up_sound if sgc2.alignedTextGrid > 0 select sgc2.alignedTextGrid Remove @@ -761,13 +759,16 @@ procedure record_sound Resample... 10000 50 Rename... Pronunciation recordedSound$ = selected$("Sound") + te.recordedSound = selected("Sound") select Sound Tmp Remove select Sound 'recordedSound$' + te.recordedSound = selected("Sound") # Cut out real sound from silences/noise call sound_detection 'recordedSound$' 'soundMargin' select Sound 'recordedSound$' + te.recordedSound = selected("Sound") endproc @@ -855,6 +856,8 @@ procedure sound_detection .sound$ .margin endif select TextGrid Input'.sound$' Remove + + select Sound '.sound$' endproc procedure end_program @@ -1128,6 +1131,8 @@ procedure printPageToPrinter endproc procedure getOpenFile .openDialogue$ + call clean_up_sound + call convert_praat_to_latin1 '.openDialogue$' .openDialogue$ = convert_praat_to_latin1.text$ .filename$ = chooseReadFile$ (.openDialogue$) @@ -1143,6 +1148,7 @@ procedure getOpenFile .openDialogue$ Create Sound from formula... Speech Mono 0 1 44100 0 endif recordedSound$ = selected$("Sound") + te.recordedSound = selected("Sound") currentStartTime = 0 currentEndTime = Get total duration # Reset selected window @@ -1785,3 +1791,21 @@ procedure emergency_table_exit .message$ endif exit '.message$' endproc + +# Remove previous files from system +procedure clean_up_sound + if recordedSound$ = "" + te.recordedSound = 0 + endif + if te.recordedSound > 0 + select te.recordedSound + Remove + recordedSound$ = "" + te.recordedSound = 0 + endif + if te.recordedPitch > 0 + select te.recordedPitch + Remove + te.recordedPitch = 0 + endif +endproc -- 2.11.4.GIT