Reading a TextGrid file into NLTK

假如想象 提交于 2019-12-24 18:11:14

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/19340155/reading-a-textgrid-file-into-nltk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!