0

I was trying to replace certain selections of sounds with silences, but before I could get into the essential part, the "Get label from interval" command failed before I was able to check whether I'd obtained the correct output.

Error Message I've Got on Praat

I'd thought it was some problems with the toy audio I played with, so I switched to another one but strangely enough, every time I always got stuck with the third interval in the sequence. Screenshot available here:

The Third Interval was Strangely not Available

The code I'm using right now is quite simple as below: There could be problems with how I process the intervals labelled as "sounding", but it should not be relevant to the error I got here.

----------------------------------------------------------------------------

soundname$ = chooseReadFile$: "Open a sound file"
sound = Read from file: soundname$
gridname$ = chooseReadFile$: "Select the corresponding TextGrid file."
grid = Read from file: gridname$


tier = 1
soundEnd = Get total duration

numOfIntervals = Get number of intervals: tier
writeInfoLine: "Number of Intervals:", numOfIntervals
appendInfoLine: "**** Starting to Replace Selected Sounds... ****"

for interval from 1 to numOfIntervals
    appendInfoLine: "Interval#", interval
    label$ = Get label of interval: tier, interval
    appendInfoLine: "Interval#", interval, ": ", label$
    if label$ == "sounding"
        startTime = Get starting point: tier, interval
        endTime = Get end point: tier, interval
        newSilence = Create Sound from formula: "new_silence", 1, startTime, endTime, 44100, ~ 0
        before = Extract part: 0, startTime, "rectangular", 1, "no"
        after = Extract part: endTime, soundEnd, "rectangular", 1, "no"
        selectObject: before, newSilence, after
        new = Concatenate
        Write to WAV file... "new".wav
        removeObject: before, newSilence, after
    endif
endfor

appendInfoLine: "Finish!"

----------------------------------------------------------------------------

I'd suspected that it was because of my editing that some shifts occurred in the TextGrid-- however, since I only supplanted the sounds with silences that were of the same length, there should not be impacts on sounds or TextGrids afterwards. However, since I never had the chance to output some playable audio results, all I inferred above could not be corroborated by solid truth.

Thank you all so much for your kind attention and help in advance!

  • You need to select the text grid at the beginning of every iteration because you select other objects in the process. Try adding `selectObject: grid` as the first line within the loop. – Stefano Aug 01 '19 at 07:07
  • @Stefano Thank you so much for your kind reply! It worked in my case though there's still some new error tangential to this question I put up. I'd be working to solve it soon and see the script smoothly running! Thanks again for your helpful guidance! – Astromsoc Aug 06 '19 at 18:32

0 Answers0