From 4c402ab5021b4cbc51d3303c3290f8fa8f3ed545 Mon Sep 17 00:00:00 2001 From: Rob van Son Date: Fri, 29 May 2015 15:36:31 +0200 Subject: [PATCH] Test of pinyin to number conversion for input --- InitialiseSGC2.praat | 3 ++- MainPage.praat | 32 ++++++++++++++++++++++++++------ sgc2.praat | 6 ++++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/InitialiseSGC2.praat b/InitialiseSGC2.praat index d4abfab..ba24fdc 100644 --- a/InitialiseSGC2.praat +++ b/InitialiseSGC2.praat @@ -211,7 +211,8 @@ procedure init_window sgc.pinyin$ = "" select Table 'wordlist$' if sgc.currentWord > 0 and sgc.currentWord <= sgc.numberOfWords - sgc.pinyin$ = Get value... 'sgc.currentWord' Pinyin + call readPinyin 'sgc.currentWord' + sgc.pinyin$ = readPinyin.pinyin$ .outputName$ = "'sgc.saveAudio$'/'sgc.pinyin$'.wav" if fileReadable(.outputName$) sgc.recordedSound = Read from file: .outputName$ diff --git a/MainPage.praat b/MainPage.praat index 7c3f949..6777db7 100644 --- a/MainPage.praat +++ b/MainPage.praat @@ -319,7 +319,8 @@ procedure generate_example if sgc.currentWord > 0 and sgc.currentWord <= sgc.numberOfWords select Table 'wordlist$' .sound$ = Get value... 'sgc.currentWord' Sound - sgc.pinyin$ = Get value... 'sgc.currentWord' Pinyin + call readPinyin 'sgc.currentWord' + sgc.pinyin$ = readPinyin.pinyin$ if .sound$ = "-" or .sound$ = "" .sound$ = sgc.pinyin$+".wav" endif @@ -365,7 +366,8 @@ procedure draw_tone_contour select Table 'wordlist$' if sgc.currentWord > 0 and sgc.currentWord <= sgc.numberOfWords .sound$ = Get value... 'sgc.currentWord' Sound - sgc.pinyin$ = Get value... 'sgc.currentWord' Pinyin + call readPinyin 'sgc.currentWord' + sgc.pinyin$ = readPinyin.pinyin$ call drawToneContour 'sgc.pinyin$' 'config.register' call reset_viewport @@ -385,7 +387,8 @@ procedure recognizeTone endif .sound$ = Get value... 'sgc.currentWord' Sound - sgc.pinyin$ = Get value... 'sgc.currentWord' Pinyin + call readPinyin 'sgc.currentWord' + sgc.pinyin$ = readPinyin.pinyin$ call align_recordedSound 'sgc.pinyin$' call sgc_ToneProt 'recordedSound$' 'sgc.pinyin$' 'config.register' '.strict' 'config.language$' # sgc_ToneProt manipulates the sound given. Reconnect @@ -448,7 +451,8 @@ procedure display_text .color$ if sgc.currentWord > 0 and sgc.currentWord <= sgc.numberOfWords .displayText$ = "" - .displayPinyin$ = Get value... 'sgc.currentWord' Pinyin + call readPinyin 'sgc.currentWord' + .displayPinyin$ = readPinyin.pinyin$ .displayChar$ = Get value... 'sgc.currentWord' Character .displayTrans$ = Get value... 'sgc.currentWord' Translation if .displayPinyin$ <> "-" and (config.displayPinyin or sgc.writeAll) @@ -553,7 +557,7 @@ endproc # NEEDS WORK AND TESTING!! # Convert unicode Pinyin into tone numbers procedure pinyin2numbers .pinyin$ - .intermediatePinyin$ = .pinyin$ + .intermediatePinyin$ = replace_regex$(.pinyin$, "[A-Z]", "\L&", 0) # Convert all special characters to numbers # Tone 1 .intermediatePinyin$ = replace_regex$(.intermediatePinyin$, "ā([iaeouü]*)", "a\11", 0) @@ -600,11 +604,27 @@ procedure pinyin2numbers .pinyin$ .intermediatePinyin$ = replace_regex$(.intermediatePinyin$, "([aeuiov]+)([^0-9aeuiov]|$)", "\10\2", 0) # Move numbers to the end of the syllable - .intermediatePinyin$ = replace_regex$(.intermediatePinyin$, "([aeuiov])([0-9])((ng?)([^aeuiov]|$))?", "\1\3\2\4", 0) + # Syllables ending in (ng?) + .intermediatePinyin$ = replace_regex$(.intermediatePinyin$, "([aeuiov])([0-9])(ng?)([^aeuiov]|$)", "\1\3\2\4", 0) + # Syllables ending in r + .intermediatePinyin$ = replace_regex$(.intermediatePinyin$, "([aeuiov])([0-9])(r)([^aeuiov]|$)", "\1\3\2\4", 0) + # Other syllables + .intermediatePinyin$ = replace_regex$(.intermediatePinyin$, "([aeuiov])([0-9])(n)", "\1\3\2", 0) + # Remove quotes etc + .intermediatePinyin$ = replace_regex$(.intermediatePinyin$, "[\\']", "", 0) .numberstext$ = .intermediatePinyin$ endproc +procedure readPinyin .currentWord + select Table 'wordlist$' + .pinyin$ = Get value... '.currentWord' Pinyin + if index_regex(.pinyin$, "[āēūīōǖáéúíóǘǎěǔǐǒǚàèùìòǜåe̊ůi̊o̊ü̊̊]") + call pinyin2numbers '.pinyin$' + .pinyin$ = pinyin2numbers.numberstext$ + endif +endproc + # Includes include ToneProt/SGC_ToneProt.praat include ToneProt/DrawToneContour.praat diff --git a/sgc2.praat b/sgc2.praat index 463157b..299db30 100644 --- a/sgc2.praat +++ b/sgc2.praat @@ -714,7 +714,8 @@ procedure count_syllables select Table 'wordlist$' if sgc.currentWord > 0 and sgc.currentWord <= sgc.numberOfWords .sound$ = Get value... 'sgc.currentWord' Sound - .pinyin$ = Get value... 'sgc.currentWord' Pinyin + call readPinyin 'sgc.currentWord' + .pinyin$ = readPinyin.pinyin$ endif call add_missing_neutral_tones '.pinyin$' .pinyin$ = add_missing_neutral_tones.pinyin$ @@ -843,7 +844,8 @@ procedure record_sound .recordingTime .pinyin$ = "" select Table 'wordlist$' if sgc.currentWord > 0 and sgc.currentWord <= sgc.numberOfWords - .pinyin$ = Get value... 'sgc.currentWord' Pinyin + call readPinyin 'sgc.currentWord' + .pinyin$ = readPinyin.pinyin$ .outputName$ = "'sgc.saveAudio$'/'.pinyin$'.wav" select sgc.recordedSound Save as WAV file: .outputName$ -- 2.11.4.GIT