1

Can anyone make a PRAAT script that deletes line breaks from intervals in Text Grids.

I did a bunch of transcribing of a word/sentence list. I copy and pasted from a text file that had line breaks between words.

For example, if you say GET INTERVAL LABEL, the transcription will be

feet
foot
one

I would like a way to delete the line breaks:

feet foot one

I realize I'm asking someone to make a script for me, which is asking for a lot. But, I'm new to programming/PRAAT scripting. I think it would be pretty easy and just involve a find/replace function loop.

Thanks,

2 Answers 2

1

You don't need to use an external editor for this. You can make use of the Replace interval text... command (you might have to upgrade Praat to a recent version if you don't have this command).

Depending on how your newlines are encoded, this should do the trick. This will loop through all the tiers in the selected TextGrid and check whether it is an interval or point tier. In each case, the appropriate command to replace labels will be used.

The command uses 6 arguments: the tier to process, the beginning and the end of the point/interval range to process (0 meaning all items), the string to match and its replacement, and whether the match should be done using regular expressions.

# Run with a single TextGrid selected
# (or include in a larger script to process multiple objects)
for tier to do("Get number of tiers")
  # Use appropriate replace command for interval and point tiers
  # The command will replace all instances of "\n" by " " in all
  # interval / point labels.
  if do("Is interval tier...", tier)
    Replace interval text: tier, 0, 0, "\n", " ", "Regular Expressions"
  else
    Replace point text:    tier, 0, 0, "\n", " ", "Regular Expressions"
  endif
endfor
3
  • Hi jja. I just upgraded to the newest version of PRAAT. I cannot get this to run. Do I have to substitute the name of my interval into part of the code above?
    – axme100
    Oct 23, 2015 at 2:03
  • 1
    Could you please use some comments to explain what's happening in the text above?
    – axme100
    Oct 23, 2015 at 2:06
  • Hard to debug without knowing what the problem is: what do you mean by "cannot get this to run"? Are you getting an error message? If so: what does it say? The script above runs for all tiers, so no: you don't need to specify the tier name. The replacement uses regular expressions, and expects your newlines to be matched by \n. I'll add some comments, but the code is pretty self-explanatory.
    – jja
    Oct 24, 2015 at 13:03
0

TextGrids are still just text files. The simplest thing for a non-scripter is probably to open it in your favorite editor and find-replace them there. Try TextWrangler or SublimeText 3 if you don’t have a good one you like.

(I’m not sure that this is even the correct StackExchange for this, or if the tags ‘phonetics’ and ‘computational-linguistics' are relevant.)

So, the tiers probably contain intervals like:

intervals [7]:
    xmin = 1.05
    xmax = 1.27
    text = “feet\nfoot\none”

While a dedicated script (sed, awk, Python, …) would be better if this is a common operation, you can indeed do this in e.g., SublimeText. One method is to first select all the ‘text' lines (e.g., Find All with '.+text.+' is fine); then, Replace All '\\n' with ‘ ‘.

This method assumes that you can't simply do a global replace of '\\n' with ' '. I think this latter, simpler option should be tried first, though.

4
  • 1
    A sed or awk script deleting line breaks is easy to write. Praat is not the tool to use for text manipulations.
    – jlawler
    Oct 22, 2015 at 23:59
  • Can you tell me how to o this on SublimeText 2 or 3? Praat Text Grids contain more than just what I have transcribed such as timestamps. How do I do find and replace on only the lines that contain my text?
    – axme100
    Oct 23, 2015 at 2:59
  • @jlawler While I agree with that, I think Praat is the tool to use for manipulating of Praat objects (unless there are special circumstances).
    – jja
    Oct 24, 2015 at 13:13
  • Yes, if it’s a common, useful manipulation of a Praat object. This seems like a one-off to fix a mistake in data prep. But whatever works, works. :) Oct 24, 2015 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.