From 1bf69b1a307974aae69f98a2c569df0f60461f3a Mon Sep 17 00:00:00 2001 From: Rob van Son Date: Tue, 28 Oct 2014 09:54:35 +0100 Subject: [PATCH] Made recording time fit the utterance --- MainPage.praat | 4 +++- ToneProt/DrawToneContour.praat | 3 +++ ToneProt/HumToneContour.praat | 3 +++ ToneProt/SGC_ToneProt.praat | 18 ++++++++++++++++++ ToneProt/ToneRecognition.praat | 3 +++ sgc2.praat | 19 +++++++++++++++++-- 6 files changed, 47 insertions(+), 3 deletions(-) diff --git a/MainPage.praat b/MainPage.praat index 03d6b2f..2ceb96e 100644 --- a/MainPage.praat +++ b/MainPage.praat @@ -238,7 +238,9 @@ procedure processMainPagePlay .clickX .clickY .pressed$ endproc procedure processMainPageRecord .clickX .clickY .pressed$ - call record_sound + call count_syllables + .recordingTime = recordingTime + ceiling((count_syllables.number - 2)/3) + call record_sound '.recordingTime' call recognizeTone # Wipe screen diff --git a/ToneProt/DrawToneContour.praat b/ToneProt/DrawToneContour.praat index dce1458..b5e4a03 100644 --- a/ToneProt/DrawToneContour.praat +++ b/ToneProt/DrawToneContour.praat @@ -11,6 +11,9 @@ procedure drawToneContour drawToneContour.pinyin$ drawToneContour.register if drawToneContour.pinyin$ <> "" drawToneContour.pinyin$ = replace_regex$(drawToneContour.pinyin$, "^\s*(.+)\s*$", "\1", 1) drawToneContour.pinyin$ = replace_regex$(drawToneContour.pinyin$, "5", "0", 0) + if index_regex(drawToneContour.pinyin$, "[0-9]") <=0 + drawToneContour.pinyin$ = drawToneContour.pinyin$+"0" + endif endif # Generate reference example diff --git a/ToneProt/HumToneContour.praat b/ToneProt/HumToneContour.praat index 8ce8d66..7c86a9c 100644 --- a/ToneProt/HumToneContour.praat +++ b/ToneProt/HumToneContour.praat @@ -11,6 +11,9 @@ procedure humToneContour humToneContour.pinyin$ humToneContour.register if humToneContour.pinyin$ <> "" humToneContour.pinyin$ = replace_regex$(humToneContour.pinyin$, "^\s*(.+)\s*$", "\1", 1) humToneContour.pinyin$ = replace_regex$(humToneContour.pinyin$, "5", "0", 0) + if index_regex(humToneContour.pinyin$, "[0-9]") <=0 + humToneContour.pinyin$ = humToneContour.pinyin$+"0" + endif endif # Generate reference example diff --git a/ToneProt/SGC_ToneProt.praat b/ToneProt/SGC_ToneProt.praat index 97584e1..74e81f4 100644 --- a/ToneProt/SGC_ToneProt.praat +++ b/ToneProt/SGC_ToneProt.praat @@ -46,6 +46,10 @@ procedure sgc_ToneProt sgc_ToneProt.currentSound$ sgc_ToneProt.pinyin$ sgc_ToneP # Clean up input if sgc_ToneProt.pinyin$ <> "" + if index_regex(sgc_ToneProt.pinyin$, "[0-9]") <=0 + sgc_ToneProt.pinyin$ = sgc_ToneProt.pinyin$+"0" + endif + sgc_ToneProt.pinyin$ = replace_regex$(sgc_ToneProt.pinyin$, "^\s*(.+)\s*$", "\1", 1) sgc_ToneProt.pinyin$ = replace_regex$(sgc_ToneProt.pinyin$, "5", "0", 0) endif @@ -89,9 +93,17 @@ procedure sgc_ToneProt sgc_ToneProt.currentSound$ sgc_ToneProt.pinyin$ sgc_ToneP sgc_ToneProt.durationModel = Get total duration maximumModelFzero = Get quantile... 0 0 0.95 Hertz minimumModelFzero = Get quantile... 0 0 0.05 Hertz + if maximumModelFzero = undefined + maximumModelFzero = 0 + endif + if minimumModelFzero = undefined + minimumModelFzero = 0 + endif sgc_ToneProt.modelPitchRange = 2 if minimumModelFzero > 0 sgc_ToneProt.modelPitchRange = maximumModelFzero / minimumModelFzero + else + sgc_ToneProt.modelPitchRange = 0 endif # Get the sounds @@ -157,6 +169,12 @@ procedure sgc_ToneProt sgc_ToneProt.currentSound$ sgc_ToneProt.pinyin$ sgc_ToneP endif sgc_ToneProt.newUpperRegister = maximumRecFzero / maximumModelFzero * sgc_ToneProt.upperRegisterInput sgc_ToneProt.newToneRange = recPitchRange / sgc_ToneProt.modelPitchRange + if sgc_ToneProt.newUpperRegister = undefined + sgc_ToneProt.newUpperRegister = sgc_ToneProt.upperRegisterInput + endif + if sgc_ToneProt.newToneRange = undefined + sgc_ToneProt.newToneRange = 1 + endif sgc_ToneProt.registerUsed$ = "OK" rangeUsed$ = "OK" diff --git a/ToneProt/ToneRecognition.praat b/ToneProt/ToneRecognition.praat index 4b4412f..7c92704 100644 --- a/ToneProt/ToneRecognition.praat +++ b/ToneProt/ToneRecognition.praat @@ -8,6 +8,9 @@ procedure FreeToneRecognition .pinyin$ .test_word$ .exclude$ .upperRegister .fre if .pinyin$ <> "" .pinyin$ = replace_regex$(.pinyin$, "^\s*(.+)\s*$", "\1", 1) .pinyin$ = replace_regex$(.pinyin$, "5", "0", 0) + if index_regex(.pinyin$, "[0-9]") <=0 + .pinyin$ = .pinyin$+"0" + endif endif .referenceFrequency = 300 diff --git a/sgc2.praat b/sgc2.praat index 6ac0259..c306e6c 100644 --- a/sgc2.praat +++ b/sgc2.praat @@ -691,6 +691,18 @@ procedure keyPressed table$ .pressed$ endfor endproc +procedure count_syllables + .number = 0 + .pinyin$ = "" + select Table 'wordlist$' + if te.currentWord > 0 and te.currentWord <= te.numberOfWords + .sound$ = Get value... 'te.currentWord' Sound + .pinyin$ = Get value... 'te.currentWord' Pinyin + endif + if index_regex(.pinyin$, "[0-9]") > 0 + .number = length(replace_regex$(.pinyin$, "[^\d]+([\d]+)", "1", 0)) + endif +endproc procedure play_sound .sound$ if .sound$ <> "" @@ -699,7 +711,10 @@ procedure play_sound .sound$ endif endproc -procedure record_sound +procedure record_sound .recordingTime + if .recordingTime <= 0 + .recordingTime = recordingTime + endif call clean_up_sound if sgc2.alignedTextGrid > 0 select sgc2.alignedTextGrid @@ -716,7 +731,7 @@ procedure record_sound # Recording light demo Paint circle... Red 5 95 2 demoShow() - noprogress nowarn Record Sound (fixed time)... 'config.input$' 0.99 0.5 'samplingFrequency' 'recordingTime' + noprogress nowarn Record Sound (fixed time)... 'config.input$' 0.99 0.5 'samplingFrequency' '.recordingTime' demo Paint circle... White 5 95 2.5 call wipeArea 'wipeFeedbackArea$' -- 2.11.4.GIT