Textgrid

Interface

TextGrid

The class TextGrid represents a Praat text grid. It has members:

xmin
The start time of the span covered by the grid.
xmax
The end time.
tiers
A list of Tier instances.

In addition, a TextGrid provides the following methods:

TextGrid(f)
The argument f is optional. If provided, it is a pathname that is passed to load().
load(f)
Load the contents from filename f.
save(f)
Save it to a file with filename f.
len(g)
The number of tiers.
g[i]
Returns the i-th tier.
g[i,j]
Returns the j-th element of the i-th tier.
del g[i]
Delete the i-the tier.
add_tier(t,n)
Add a new tier of type t with name n. The type should be either 'IntervalTier' or 'TextTier'.
clone()
Creates a new copy of the text grid. The tiers are not\/ copied. One should be sure to clone any of the tiers that one wishes to modify, e.g.:
>>> grid[2] = grid[2].clone()

Tier

A Tier is created by calling the TextGrid method add{\underscoretier()}.

type
Either 'IntervalTier' or 'TextTier'.
dtype
The actualy type of the elements, which is either Interval or Point.
name
The name.
xmin
Inherited from the TextGrid.
xmax
Inherited from the TextGrid.
contents
A list of elements, which are either Intervals or Points.
symtab
If the tier has been converted to an array, this will contain the symbol table used. It maps strings to ints.

A Tier also provides the following methods:

len(t)
The number of elements in the tier.
t[i]
The i-th element.
x()
The last time point covered by an element in the contents. A freshly-created tier is empty, and the value is xmin. As elements are added to the tier, the value is the xmax of the most recently added element.
add(...)
Add an element to the tier. The arguments ... are passed to the element constructor.
array()
Returns a time series, that is, a two-column matrix in which the first column is a time point and the second column contains symbol codes. The symbol table used to convert strings to symbol codes is stored in member symtab. There is one row for each element in the tier. The time points are obtained by calling center() on each element, and the symbol codes are obtained by calling symbol().
clone()
Creates an identical but independent copy of the tier. All elements are also copied.

Interval

An Interval has the members:

tier
The tier that it belongs to.
xmin
Its start time.
xmax
Its end time.
text
A string.

The following methods are provided:

string()
Returns the text.
center()
Returns the mean of xmin and xmax.
symbol(T)
Returns the result of interning the text in the symbol table T.

In general, one only creates an Interval by calling the add() method of a Tier. One should provide the keyword arguments text and xmax.

Point

A Point has the following members:

tier
The tier that it belongs to.
number
The time (a float).
mark
A string.
string()
Returns the mark.
center()
Returns the time.
symbol(T)
Interns the mark in the symbol table T and returns the resulting code.

In general, one only creates a Point by calling the add() method of a Tier. One should provide the keyword arguments number and mark.