1

I am new to praat, so maybe this is an easy question. I try to create a script in praat that will go through some objects in my object list with a for loop and will remove silent intervals. I have created this script that I will put in a for loop.

selectObject: i
inten=To Intensity... 100 0 "no"
txt=To TextGrid (silences)... -35 0.1 0.05 'silent' 'sounding'
selectObject: i
plusObject: txt
Extract intervals where: 1, "no", "contains", "sounding"
myobj=Concatenate
Copy: string$(i)
selectObject: inten
plusObject: txt
plusObject: myobj
Remove

Although I get what I want my problem is in the line

Extract intervals where: 1, "no", "contains", "sounding"

In this line the parts that contain sound are extracted and selected. Then I use concatenate immediately to create the desired file and select it. However because this line produces more that one variable I cannot save it. Therefore later on I do not have a reference to remove it from my object directory. Although I could still run it like that my directory would be flooded and I do not think this is elegant. Any suggestions?

Dimitris
  • 560
  • 3
  • 17

1 Answers1

2

This might sound obvious, but you can save the ID numbers of the multiple extracted intervals by saving each of them into an indexed variable, and then re-selecting them when you need to remove them.

Below you'll find an edited and commented version of your script. I changed some variable names to make it easier to follow.

sound = selected()
intensity = To Intensity: 100, 0, "no"
textgrid = To TextGrid (silences): -35, 0.1, 0.05, silent, sounding

# Select multiple objects at once
selectObject: sound, textgrid

Extract intervals where: 1, "no", "contains", "sounding"

# Save the ID numbers of the currently selected intervals
total_parts = numberOfSelected()
for i to total_parts
  part[i] = selected(i)
endfor

# No need to make a copy just to rename
sounding = Concatenate
Rename: string$(sound)

# Select all the objects you want to remove
selectObject: intensity, textgrid
# Including the extracted intervals
for i to total_parts
  plusObject: part[i]
endfor
# And remove them
Remove

# If you knew beforehand what objects to select,
# you could also use removeObject()

# Select your concatenated sound
selectObject: sounding

As an aside, the selection plugin available through CPrAN was written to make it easier to manage Praat object selections for cases such as this. The two loops inserted above could have been replaced with calls to @saveSelection() and @restoreSelection() (full disclosure: I wrote that plugin).

jja
  • 2,058
  • 14
  • 27
  • Like I said I am new to praat, so not obvious at all. Thanks a lot! – Dimitris Jan 14 '16 at 15:25
  • Hi there, I know this is an old question, but this script doesn't seem to work for me. The script all makes sense to me except for the `sounding = Concatenate Rename: string$(sound)` part. Also, the second for loop seems to just be selecting the objects that have been created, not the intervals in the original sound file. Thanks! – Lisa Oct 07 '18 at 12:53
  • @Lisa The script uses `Extract intervals` to turn each "sounding" interval into a new `Sound` object, and uses `Concatenate` to merge them all into a single new `Sound` object and `Rename` so it has a sensible name. The second loop _is_ selecting the objects that were created so we can `Remove` them. I call them "extracted intervals" because each of them represents one of the intervals we extracted before. So it's not the intervals in the `TextGrid`, but the objects with the data in those intervals in the `Sound` object. Is that clearer? Also: how exactly is this not working for you? – jja Oct 08 '18 at 09:31