# Path: praatio/praatio_scripts.py
# class NameStyle:
#     APPEND = "append"
#     APPEND_NO_I = "append_no_i"
#     LABEL = "label"
# def _shiftTimes(
#     tg: textgrid.Textgrid, timeV: float, newTimeV: float
# ) -> textgrid.Textgrid:
# def audioSplice(
#     audioObj: audio.WavObj,
#     spliceSegment: audio.WavObj,
#     tg: textgrid.Textgrid,
#     tierName: str,
#     newLabel: str,
#     insertStart: float,
#     insertStop: float = None,
#     alignToZeroCrossing: bool = True,
# ) -> Tuple[audio.WavObj, textgrid.Textgrid]:
# def spellCheckEntries(
#     tg: textgrid.Textgrid,
#     targetTierName: str,
#     newTierName: str,
#     checkFunction: Callable[[str], bool],
#     printEntries: bool = False,
# ) -> textgrid.Textgrid:
# def splitTierEntries(
#     tg: textgrid.Textgrid,
#     sourceTierName: str,
#     targetTierName: str,
#     startT: float = None,
#     endT: float = None,
# ) -> textgrid.Textgrid:
# def tgBoundariesToZeroCrossings(
#     tg: textgrid.Textgrid,
#     wavObj: audio.WavObj,
#     adjustPointTiers: bool = True,
#     adjustIntervalTiers: bool = True,
# ) -> textgrid.Textgrid:
# def splitAudioOnTier(
#     wavFN: str,
#     tgFN: str,
#     tierName: str,
#     outputPath: str,
#     outputTGFlag: bool = False,
#     nameStyle: Optional[Literal["append", "append_no_i", "label"]] = None,
#     noPartialIntervals: bool = False,
#     silenceLabel: str = None,
# ) -> List[Tuple[float, float, str]]:
#     def getValue(myBool) -> Literal["strict", "lax", "truncated"]:
# def alignBoundariesAcrossTiers(
#     tgFN: str, maxDifference: float = 0.01
# ) -> textgrid.Textgrid:
# def _findMisalignments(
#     tg: textgrid.Textgrid,
#     timeV: float,
#     maxDifference: float,
#     tierNameList: List[str],
#     tierName: str,
#     entry: list,
#     orderID: int,
# ) -> None:


import os
from os.path import join
from praatio import praatio_scripts
"""
Praatio example of correcting small differences in boundaries across different tiers

This problem can happen when annotators are not careful
to align boundaries at the same time.
"""


path = join(".", "files")
outputPath = join(path, "aligned-tier_textgrids")

inputFN = join(path, "mary_misaligned.TextGrid")
outputFN = join(outputPath, "mary_aligned.TextGrid")
maxDifference = 0.01

if not os.path.exists(outputPath):
    os.mkdir(outputPath)


# Path: praatio/praatio_scripts.py
# class NameStyle:
#     APPEND = "append"
#     APPEND_NO_I = "append_no_i"
#     LABEL = "label"
# def _shiftTimes(
#     tg: textgrid.Textgrid, timeV: float, newTimeV: float
# ) -> textgrid.Textgrid:
# def audioSplice(
#     audioObj: audio.WavObj,
#     spliceSegment: audio.WavObj,
#     tg: textgrid.Textgrid,
#     tierName: str,
#     newLabel: str,
#     insertStart: float,
#     insertStop: float = None,
#     alignToZeroCrossing: bool = True,
# ) -> Tuple[audio.WavObj, textgrid.Textgrid]:
# def spellCheckEntries(
#     tg: textgrid.Textgrid,
#     targetTierName: str,
#     newTierName: str,
#     checkFunction: Callable[[str], bool],
#     printEntries: bool = False,
# ) -> textgrid.Textgrid:
# def splitTierEntries(
#     tg: textgrid.Textgrid,
#     sourceTierName: str,
#     targetTierName: str,
#     startT: float = None,
#     endT: float = None,
# ) -> textgrid.Textgrid:
# def tgBoundariesToZeroCrossings(
#     tg: textgrid.Textgrid,
#     wavObj: audio.WavObj,
#     adjustPointTiers: bool = True,
#     adjustIntervalTiers: bool = True,
# ) -> textgrid.Textgrid:
# def splitAudioOnTier(
#     wavFN: str,
#     tgFN: str,
#     tierName: str,
#     outputPath: str,
#     outputTGFlag: bool = False,
#     nameStyle: Optional[Literal["append", "append_no_i", "label"]] = None,
#     noPartialIntervals: bool = False,
#     silenceLabel: str = None,
# ) -> List[Tuple[float, float, str]]:
#     def getValue(myBool) -> Literal["strict", "lax", "truncated"]:
# def alignBoundariesAcrossTiers(
#     tgFN: str, maxDifference: float = 0.01
# ) -> textgrid.Textgrid:
# def _findMisalignments(
#     tg: textgrid.Textgrid,
#     timeV: float,
#     maxDifference: float,
#     tierNameList: List[str],
#     tierName: str,
#     entry: list,
#     orderID: int,
# ) -> None:


# Path: examples/correct_misaligned_tiers.py
import os
from os.path import join
from praatio import praatio_scripts

"""
Praatio example of correcting small differences in boundaries across different tiers

This problem can happen when annotators are not careful
to align boundaries at the same time.
"""


path = join(".", "files")
outputPath = join(path, "aligned-tier_textgrids")

inputFN = join(path, "mary_misaligned.TextGrid")
outputFN = join(outputPath, "mary_aligned.TextGrid")
maxDifference = 0.01

if not os.path.exists(outputPath):
    os.mkdir(outputPath)


tg = praatio_scripts.alignBoundariesAcrossTiers(inputFN, maxDifference)