将TextGrid文件读入NLTK [英] Reading a TextGrid file into NLTK
问题描述
我正在尝试将TextGrid文件读入NLTK,但是遇到了一些麻烦. 我了解有Textgrid解析器(如此处所示: http://nltk.googlecode.com/svn/trunk/nltk_contrib/nltk_contrib/textgrid.py ).
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).
不幸的是,我是NLTK的新手,我也不知道如何使用解析器.
Unfortunately, I'm new to NLTK, and I have no idea how to use the parser.
任何帮助将不胜感激.
推荐答案
不幸的是,了解NLTK并没有帮助:我看了一下textgrid的源代码,尽管它是由NLTK的核心团队编写的与其他NLTK语料库阅读器"没有任何共同之处.我建议您研究源代码中的文件头并进行一些试验-该文档原本就足够了.
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.
入门:看起来您可以通过将打开的文件指针传递给类TextGrid
的构造函数来加载TextGrid文件:
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.这不是一个很完整的答案,但是我不能在注释中包含代码段.
PS. This is not a very complete answer, but I can't include a code snippet in a comment.
这篇关于将TextGrid文件读入NLTK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!