From 287fd1c68e71f25437259d6815da9f21c92f3d56 Mon Sep 17 00:00:00 2001 From: Rob van Son Date: Mon, 5 Jan 2015 15:37:54 +0100 Subject: [PATCH] Added evaluation of stored audio recordings --- InitialiseSGC2.praat | 23 +++++++++++++++++++++++ MainPage.praat | 18 +++++++++++++++++- sgc2.praat | 6 ++++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/InitialiseSGC2.praat b/InitialiseSGC2.praat index c506a3a..9d25603 100644 --- a/InitialiseSGC2.praat +++ b/InitialiseSGC2.praat @@ -62,6 +62,7 @@ config$ = "" wordlistNum = 1 wordlistName$ = "" wordlist$ = "" +mainPage.play = -1 config.deleteWordlist = -1 config.displayNumbers = 1 config.displayPinyin = 1 @@ -181,6 +182,23 @@ procedure init_window demo 'defaultFont$' call set_font_size 'defaultFontSize' demo Black + + # If there is no recorded sound, try to read stored recording + if recordedSound$ = "" and config.saveAudio$ <> "" + .pinyin$ = "" + select Table 'wordlist$' + if te.currentWord > 0 and te.currentWord <= te.numberOfWords + .pinyin$ = Get value... 'te.currentWord' Pinyin + .outputName$ = "'config.saveAudio$'/'.pinyin$'.wav" + if fileReadable(.outputName$) + te.recordedSound = Read from file: .outputName$ + recordedSound$ = selected$("Sound") + call recognizeTone + endif + endif + endif + + # Update screen call reset_viewport .windowTitle$ = replace$(wordlistName$, "_", " ", 0) call set_window_title 'buttons$' '.windowTitle$' @@ -193,10 +211,15 @@ procedure init_window endif # Define buttons in a table call init_buttons + # Set Play button + call Set_Play_Button + # Draw the contour call draw_tone_contour # Logging light call paint_saveAudio_light + # Set play button + endproc # Make sure all Preferences directories are available diff --git a/MainPage.praat b/MainPage.praat index f2a4b1a..2ec4297 100644 --- a/MainPage.praat +++ b/MainPage.praat @@ -234,7 +234,21 @@ procedure processMainPageHelp .clickX .clickY .pressed$ endproc procedure processMainPagePlay .clickX .clickY .pressed$ - call play_sound 'recordedSound$' + .table$ = "MainPage" + .label$ = "Play" + if recordedSound$ <> "" + call play_sound 'recordedSound$' + mainPage.play = 0 + endif + te.buttonPressValue = mainPage.play +endproc + +procedure Set_Play_Button + mainPage.play = -1 + if recordedSound$ <> "" + mainPage.play = 0 + endif + call Draw_button MainPage Play 'mainPage.play' endproc procedure processMainPageRecord .clickX .clickY .pressed$ @@ -245,6 +259,8 @@ procedure processMainPageRecord .clickX .clickY .pressed$ endif call record_sound '.recordingTime' call recognizeTone + mainPage.play = 0 + call Set_Play_Button # Wipe screen call wipeArea 'wipeContourArea$' diff --git a/sgc2.praat b/sgc2.praat index bf2cb76..6d976ef 100644 --- a/sgc2.praat +++ b/sgc2.praat @@ -42,6 +42,7 @@ config$ = "" recordedSound$ = "" te.recordedSound = 0 te.recordedPitch = 0 +te.buttonPressValue = 0 samplingFrequency = 44100 recordingTime = 2 @@ -120,11 +121,12 @@ while demoWaitForInput() # Do things if .label$ != "" + te.buttonPressValue = 0 # Push button down call Draw_button 'buttons$' '.label$' 1 call process_label '.label$' '.clickX' '.clickY' '.pressed$' # push button up - call Draw_button 'buttons$' '.label$' 0 + call Draw_button 'buttons$' '.label$' 'te.buttonPressValue' endif endwhile @@ -171,7 +173,7 @@ procedure Draw_all_buttons .table$ # A variable with the same name as the button will act as a # "pressed state" .variableName$ = .varPrefix$+"."+(replace_regex$(.label$, "^(.)", "\l\1", 0)) - # Simple boolean vairables + # Simple boolean variables if index(.variableName$, "_") <= 0 and variableExists(.variableName$) # True: Pressed if '.variableName$' > 0 -- 2.11.4.GIT