ExtractAndSaveSounds

# This is developed using praat version 5.3.73
form Extract and save sounds
        sentence Path /home/user
        natural Tier 1
endform

if right$(path$,1) != "/"
        path$=path$+"/"
endif

# uncomment to pre-polulate opbject list
#ss1=Create SpeechSynthesizer: "English", "default"
#To Sound: "This is some text.", "yes"

ns=numberOfSelected("Sound")
ntg=numberOfSelected("TextGrid")
if ns != 1 or ntg != 1
        exit Please select exactly 1 Sound and 1 TextGrid!
endif

s1=selected("Sound")
tg1=selected("TextGrid")

Extract non-empty intervals: tier, "no"

nSounds=numberOfSelected("Sound")

for i from 1 to nSounds
        sels[i] = selected("Sound",i)
endfor

select 's1'

name1$=selected$("Sound")
for i from 1 to nSounds
        selectObject: sels[i]
        name2$=selected$("Sound")
        outName$=path$+name1$+"_"+name2$+".wav"
        Save as WAV file: outName$
        Remove
endfor