o
    xiY                     @   s   d Z ddlZddlmZmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ 		ddededed ded def
ddZdeded defddZdS )a  
Functions for reading/writing/manipulating textgrid files.

This file links the main data structures for representing Textgrid data:
Textgrid, IntervalTier, and PointTier

A Textgrid is a container for multiple annotation tiers.  Tiers can contain
either interval data (IntervalTier) or point data (PointTier).
Tiers in a Textgrid are ordered and must contain a unique name.

openTextgrid() can be used to open a textgrid file.
Textgrid.save() can be used to save a Textgrid object to a file.

Historically, these three classes lived in this file. To
make maintance easier, they were split off.  You can still access
them from this file as before, but please check out the respective
files for more documentation on each class:
IntervalTier in data_classes/interval_tier.py
PointTier in data_classes/point_tier.py
Textgrid in data_classes/textgrid.py

see the **examples/** directory for examples using textgrid.py
    N)UnionType)Literal)INTERVAL_TIER)IntervalTier)	PointTier)Textgrid)textgrid_io)utils)	constants)errorswarningerror
fnFullPathincludeEmptyIntervalsreportingMode)silencer   r   duplicateNamesMode)r   renamereturnc                 C   sN  t d|tj t d|tj ztj| ddd}| }W d   n1 s(w   Y  W n% tyS   tj| ddd}| }W d   n1 sLw   Y  Y nw t	
||}g }|d D ]A}|d	 }	|	|v r|tjjkrytd
|	 d|tjjkr|	}
d}|
|v r|	 d| }
|d7 }|
|v s|
}	|	|d	< ||	 q`t||S )a  Opens a textgrid file (.TextGrid and .json are both fine)

    https://www.fon.hum.uva.nl/praat/manual/TextGrid_file_formats.html

    Args:
        fnFullPath: the path to the textgrid to open
        includeEmptyIntervals: if False, points and intervals with
             an empty label '' are not included in the returned Textgrid

    Returns:
        A Textgrid

    Raises:
        DuplicateTierName: The textgrid contains multiple tiers with the same name
    r   r   rzutf-16)encodingNzutf-8tiersnamez1Your textgrid contains tiers with the same name 'z'. This is not allowed. It is recommended that you rename them. If you set openTextgrid(..., duplicateNamesMode='rename'), praatio will automatically append numbers to the end of tiers to ensure they are unique.   _   )r
   validateOptionr   ErrorReportingModeDuplicateNamesioopenreadUnicodeErrorr	   parseTextgridStrERRORr   DuplicateTierNameRENAMEappend_dictionaryToTg)r   r   r   r   fddatatgAsDict	tierNamestierr   newNamei r1   S/home/ubuntu/maya3_transcribe/venv/lib/python3.10/site-packages/praatio/textgrid.pyopenTextgrid.   sF   



r3   r,   c                 C   s~   t d|tj t }| d |_| d |_| d D ]#}|d tkr$t}nt	}||d |d |d |d }|j
||d q|S )	z@Converts a dictionary representation of a textgrid to a Textgridr   xminxmaxr   classr   entries)r   )r
   r   r   r   r   minTimestampmaxTimestampr   r   r   addTier)r,   r   tg
tierAsDictklassr.   r1   r1   r2   r)   i   s    

r)   )r   r   )__doc__r    typingr   r   typing_extensionsr   praatio.utilities.constantsr   "praatio.data_classes.interval_tierr   praatio.data_classes.point_tierr   praatio.data_classes.textgridr   praatio.utilitiesr	   r
   r   r   strboolr3   dictr)   r1   r1   r1   r2   <module>   s@    
;