1

I'm trying to read in a TextGrid file into NLTK, but I'm having some trouble. I understand that there is a parser for Textgrid ( as seen here: http://nltk.googlecode.com/svn/trunk/nltk_contrib/nltk_contrib/textgrid.py).

Unfortunately, I'm new to NLTK, and I have no idea how to use the parser.

Any help would be very appreciated.

2 Answers2

2

Unfortunately, knowing the NLTK doesn't help: I took a look at the source code for textgrid, and although it was written by the NLTK's core team it's got nothing in common with other NLTK "corpus readers". I suggest you study the file header in the source and experiment a bit-- the documentation was intended to be sufficient.

To get you started: It looks like you can load a TextGrid file by passing an open file pointer to the constructor of class TextGrid:

fp = open("grid_file.praat")
grid = TextGrid(fp)
for tier in grid:
    # do something with the Tier object

PS. This is not a very complete answer, but I can't include a code snippet in a comment.

alexis
  • 48,685
  • 16
  • 101
  • 161
0

A bit late to the party, but here I go:

You could save the TextGrid object as a JSON file and read it into NLTK using the standard python libraries as in this answer.

Praat does not include (at this time) a JSON converter, but [full disclaimer] I have been working on one such script that should do the job. It's part of a larger plugin I maintain, which can be downloaded from its github repository.

Once you install the plugin, you can use it by running

runScript: preferencesDirectory$ + "/plugin_jjatools/save_as_json.praat",
  ..."/output/path", "Data stream", "Pretty printed"

That script basically calls a perl script in the background, which does most of the hard work, so you could also just run the perl script directly. Even though it is still in development, most object types are currently supported.

Community
  • 1
  • 1
jja
  • 2,058
  • 14
  • 27