selkie.textgrid
— Praat textgrid
Interface
- class TextGrid(fn)
The class
TextGrid
represents a Praat text grid. The argument fn is optional. If provided, it is a pathname that is passed toload()
. One may also provide encoding as a keyword argument. (Note that recent versions of Praat write UTF-16 files rather than the standard UTF-8.)>>> from selkie.data import ex >>> from selkie.textgrid import TextGrid >>> grid = TextGrid(ex('northwind.TextGrid'), encoding='utf16')
A TextGrid has the following 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:- load(fn)
Load the contents from filename fn.
- save(fn)
Save it to a file with filename fn.
- __len__()
The number of tiers.
- __getitem__(idx)
If idx is an integer, returns the tier at that position. If idx is a pair (i, j), returns the j-th element of the i-th tier.
- __delitem__(i)
Delete the i-th tier.
- add_tier(type, name)
Add a new tier with the given type and name. 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[1] = grid[1].clone()
- class Tier
A
Tier
is created by calling theTextGrid
methodadd_tier()
. Although not currently enforced, the following members should be treated as read-only.- type
Either
'IntervalTier'
or'TextTier'
.
- dtype
The actual type of the elements, which is either
Interval
orPoint
.
- name
The name.
- xmin
Inherited from the
TextGrid
.
- xmax
Inherited from the
TextGrid
.
- contents
A list of elements, which are either
Intervals
orPoints
.
- 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__
The number of elements in the tier.
- __getitem__(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(*args, **kwargs)
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 callingcenter()
on each element, and the symbol codes are obtained by callingsymbol()
.
- clone
Creates an identical but independent copy of the tier. All elements are also copied.
- class Interval
In general, one only creates an
Interval
by calling theadd()
method of aTier
. One should provide the keyword argumentstext
andxmax
.An
Interval
has the following members, which should be considered read-only.- tier
The tier that it belongs to.
- xmin
Its start time.
The following methods are provided:
- string()
Returns the text.
- center()
Returns the mean of
xmin
andxmax
.
- symbol(tab)
Returns the result of interning the text in the symbol table tab.
- class Point
In general, one only creates a
Point
by calling theadd()
method of aTier
. One should provide the keyword argumentsnumber
andmark
.A
Point
has the following members, which should be considered read-only:- tier
The tier that it belongs to.
- number
The time (a float).
- mark
A string.
- string
Returns the mark.
- center
Returns the time.
- symbol(tab)
Interns the mark in the symbol table tab and returns the resulting code.