Praat¶
- class pympi.Praat.TextGrid(file_path=None, xmin=0, xmax=None, codec='ascii', stream=False)¶
Read write and edit Praat’s TextGrid files.
Note
All times are in seconds and can have decimals
Variables: - xmin (float) – Minimum x value.
- xmax (float) – Maximum x value.
- tier_num (int) – Number of tiers.
- tiers (list) – Internal (unsorted) list of tiers.
- codec (str) – Codec of the input file.
- __init__(file_path=None, xmin=0, xmax=None, codec='ascii', stream=False)¶
Construct either a new TextGrid object or read one from a file/stream. When you create an empty TextGrid you must at least specify the xmax.
Parameters: - file_path (str) – Path to read from, - for stdin. If None an empty TextGrid will be created.
- xmin (int) – Xmin value, only needed when not loading from file.
- xmax (int) – Xmax value, needed when not loading from file.
- codec (str) – Text encoding for the input.
- stream (bool) – Flag for loading from a stream(not used, only for debugging purposes)
Raises Exception: If filepath is specified but no xmax
- add_tier(name, tier_type='IntervalTier', number=None)¶
Add an IntervalTier or a TextTier on the specified location.
Parameters: - name (str) – Name of the tier, duplicate names is allowed.
- tier_type (str) – Type of the tier. (‘IntervalTier’, ‘TextTier’)
- number (int) – Place to insert the tier, when None the number is generated and the tier will be placed on the bottom.
Returns: The created tier.
Raises ValueError: If the number is out of bounds.
- change_tier_name(name_num, name2)¶
Changes the name of the tier, when multiple tiers exist with that name only the first is renamed.
Parameters: - name_num (int or str) – Name or number of the tier to rename.
- name2 (str) – New name of the tier.
Raises TierNotFoundException: If the tier doesn’t exist.
- from_stream(ifile, codec='ascii')¶
Read textgrid from stream.
Parameters: - ifile (file) – Stream to read from.
- codec (str) – Text encoding.
- get_tier(name_num)¶
Gives a tier, when multiple tiers exist with that name only the first is returned.
Parameters: name_num (int or str) – Name or number of the tier to return. Returns: The tier. Raises TierNotFoundException: If the tier doesn’t exist.
- get_tier_name_num()¶
Give all tiers with their numbers.
Returns: List consisting of the form [(num1, tier1), (num2, tier2) ... (numn, tiern)]
- get_tiers()¶
Give all tiers.
Yields: Available tiers
- remove_tier(name_num)¶
Remove a tier, when multiple tiers exist with that name only the first is removed.
Parameters: name_num (int or str) – Name or number of the tier to remove. Raises TierNotFoundException: If the tier doesn’t exist.
- to_eaf(pointlength=0.1)¶
Convert the object to an pympi.Elan.Eaf object
Parameters: pointlength (int) – Length of respective interval from points in seconds
Returns: pympi.Elan.Eaf object
Raises: - ImportError – If the Eaf module can’t be loaded.
- ValueError – If the pointlength is not strictly positive.
- to_file(filepath, codec='utf-8')¶
Write the object to a file.
Parameters: - filepath (str) – Path of the file, ‘-‘ for stdout.
- codec (str) – Text encoding.
- to_stream(f, codec='utf-8')¶
Write the object to a stream.
Parameters: - f (file) – Open stream to write to.
- codec (str) – Text encoding.
- update()¶
Update the xmin, xmax and number of tiers value
- class pympi.Praat.Tier(name, tier_type, number, lines=None, codec='ascii')¶
Class representing a TextGrid tier, either an Interval or TextTier
Variables: - name (str) – Name of the tier.
- intervals (list) – List of intervals where each interval is (start, [end,] value).
- number (int) – Number of the tier.
- tier_type (str) – Type of the tier(‘IntervalTier’ or ‘TextTier’).
- xmin (int) – Minimum x value.
- xmax (int) – Maximum x value.
- __init__(name, tier_type, number, lines=None, codec='ascii')¶
Creates a tier, if lines is None a new tier is created and codec is ignored.
Parameters: - name (str) – Name of the tier.
- tier_type (str) – Type of the tier(‘IntervalTier’ or ‘TextTier’).
- number (int) – Number of the tier.
- lines (iter) – Iterator of the input lines.
- codec (str) – Text encoding of the input.
Raises TierTypeException: If the tier type is unknown.
- add_interval(begin, end, value, check=True)¶
Add an interval to the IntervalTier.
Parameters: - begin (float) – Start time of the interval.
- end (float) – End time of the interval.
- value (str) – Text of the interval.
- check (bool) – Flag to check for overlap.
Raises: - TierTypeException – If the tier is not a IntervalTier.
- Exception – If there is already an interval in that time.
- add_point(point, value, check=True)¶
Add a point to the TextTier
Parameters: - point (int) – Time of the point.
- value (str) – Text of the point.
- check (bool) – Flag to check for overlap.
Raises: - TierTypeException – If the tier is not a TextTier.
- Exception – If there is already a point at that time.
- clear_intervals()¶
Removes all the intervals in the tier
- get_intervals(sort=False)¶
Give all the intervals or points.
Parameters: sort (bool) – Flag for yielding the intervals or points sorted. Yields: All the intervals
- remove_interval(time)¶
Remove an interval, if no interval is found nothing happens.
Parameters: time (int) – Time of the interval. Raises TierTypeException: If the tier is not a IntervalTier.
- remove_point(time)¶
Remove a point, if no point is found nothing happens.
Parameters: time (int) – Time of the point. Raises TierTypeException: If the tier is not a TextTier.
- update()¶
Update the internal values