# Path: praatio/utilities/errors.py
# class PraatioException(Exception):
# class SafeZipException(PraatioException):
# class FileNotFound(PraatioException):
# class ParsingError(PraatioException):
# class ArgumentError(PraatioException):
# class UnexpectedError(PraatioException):
# class WrongOption(PraatioException):
# class TextgridException(PraatioException):
# class DuplicateTierName(TextgridException):
# class OutOfBounds(TextgridException):
# class CollisionError(TextgridException):
# class TimelessTextgridTierException(TextgridException):
# class TextgridStateAutoModified(TextgridException):
# class TextgridStateError(TextgridException):
# class TierNameExistsError(TextgridException):
# class IncompatibleTierError(TextgridException):
# class PraatExecutionFailed(PraatioException):
# class EndOfAudioData(PraatioException):
# class FindZeroCrossingError(PraatioException):
# class NormalizationException(PraatioException):
#     def __init__(self, fullPath: str):
#     def __str__(self):
#     def __init__(self, argumentName: str, givenValue: str, availableOptions: List[str]):
#     def __str__(self):
#     def __str__(self):
#     def __init__(self, tier):
#     def __str__(self):
#     def __init__(self, cmdList: List[str]):
#     def __str__(self):
#     def __init__(self, startTime: float, endTime: float):
#     def __str__(self):
#     def __str__(self):
# 
# Path: praatio/utilities/constants.py
# INTERVAL_TIER: Final = "IntervalTier"
# POINT_TIER: Final = "TextTier"
# MIN_INTERVAL_LENGTH: Final = 0.00000001  # Arbitrary threshold
#     LONG_TEXTGRID: Final = "long_textgrid"
#     SHORT_TEXTGRID: Final = "short_textgrid"
#     JSON: Final = "json"
#     POINT: Final = "PointProcess"
#     PITCH: Final = "PitchTier"
#     DURATION: Final = "DurationTier"
#     STRICT: Final = "strict"
#     LAX: Final = "lax"
#     TRUNCATED: Final = "truncated"
#     SILENCE: Final = "silence"
#     WARNING: Final = "warning"
#     ERROR: Final = "error"
#     REPLACE: Final = "replace"
#     MERGE: Final = "merge"
#     ERROR: Final = "error"
#     STRETCH: Final = "stretch"
#     SPLIT: Final = "split"
#     NO_CHANGE: Final = "no_change"
#     ERROR: Final = "error"
#     TRUNCATE: Final = "truncate"
#     CATEGORICAL: Final = "categorical"
#     ERROR: Final = "error"
#     ERROR: Final = "error"
#     RENAME: Final = "rename"
# class Interval(namedtuple("Interval", ["start", "end", "label"])):
# class Point(namedtuple("Point", ["time", "label"])):
# class TextgridFormats:
# class DataPointTypes:
# class CropCollision:
# class ErrorReportingMode:
# class IntervalCollision:
# class WhitespaceCollision:
# class EraseCollision:
# class DuplicateNames:
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __eq__(self, other):
#     def __ne__(self, other):


import os
import subprocess
import itertools
import wave
from pkg_resources import resource_filename
from typing_extensions import Literal
from typing import Any, Iterator, List, Tuple, NoReturn, Type
from praatio.utilities import errors
from praatio.utilities import constants
    """
    indexList = []
    index = 0
    while True:
        try:
            index = txt.index(subStr, index)
        except ValueError:
            break
        indexList.append(int(index))
        index += 1

    return indexList


def runPraatScript(
    praatEXE: str, scriptFN: str, argList: List[Any], cwd: str = None
) -> None:

    # Popen gives a not-very-transparent error
    if not os.path.exists(praatEXE):
        raise errors.FileNotFound(praatEXE)
    if not os.path.exists(scriptFN):
        raise errors.FileNotFound(scriptFN)

    argList = ["%s" % arg for arg in argList]
    cmdList = [praatEXE, "--run", scriptFN] + argList

    myProcess = subprocess.Popen(cmdList, cwd=cwd)

    if myProcess.wait():

# Path: praatio/utilities/errors.py
# class PraatioException(Exception):
# class SafeZipException(PraatioException):
# class FileNotFound(PraatioException):
# class ParsingError(PraatioException):
# class ArgumentError(PraatioException):
# class UnexpectedError(PraatioException):
# class WrongOption(PraatioException):
# class TextgridException(PraatioException):
# class DuplicateTierName(TextgridException):
# class OutOfBounds(TextgridException):
# class CollisionError(TextgridException):
# class TimelessTextgridTierException(TextgridException):
# class TextgridStateAutoModified(TextgridException):
# class TextgridStateError(TextgridException):
# class TierNameExistsError(TextgridException):
# class IncompatibleTierError(TextgridException):
# class PraatExecutionFailed(PraatioException):
# class EndOfAudioData(PraatioException):
# class FindZeroCrossingError(PraatioException):
# class NormalizationException(PraatioException):
#     def __init__(self, fullPath: str):
#     def __str__(self):
#     def __init__(self, argumentName: str, givenValue: str, availableOptions: List[str]):
#     def __str__(self):
#     def __str__(self):
#     def __init__(self, tier):
#     def __str__(self):
#     def __init__(self, cmdList: List[str]):
#     def __str__(self):
#     def __init__(self, startTime: float, endTime: float):
#     def __str__(self):
#     def __str__(self):
# 
# Path: praatio/utilities/constants.py
# INTERVAL_TIER: Final = "IntervalTier"
# POINT_TIER: Final = "TextTier"
# MIN_INTERVAL_LENGTH: Final = 0.00000001  # Arbitrary threshold
#     LONG_TEXTGRID: Final = "long_textgrid"
#     SHORT_TEXTGRID: Final = "short_textgrid"
#     JSON: Final = "json"
#     POINT: Final = "PointProcess"
#     PITCH: Final = "PitchTier"
#     DURATION: Final = "DurationTier"
#     STRICT: Final = "strict"
#     LAX: Final = "lax"
#     TRUNCATED: Final = "truncated"
#     SILENCE: Final = "silence"
#     WARNING: Final = "warning"
#     ERROR: Final = "error"
#     REPLACE: Final = "replace"
#     MERGE: Final = "merge"
#     ERROR: Final = "error"
#     STRETCH: Final = "stretch"
#     SPLIT: Final = "split"
#     NO_CHANGE: Final = "no_change"
#     ERROR: Final = "error"
#     TRUNCATE: Final = "truncate"
#     CATEGORICAL: Final = "categorical"
#     ERROR: Final = "error"
#     ERROR: Final = "error"
#     RENAME: Final = "rename"
# class Interval(namedtuple("Interval", ["start", "end", "label"])):
# class Point(namedtuple("Point", ["time", "label"])):
# class TextgridFormats:
# class DataPointTypes:
# class CropCollision:
# class ErrorReportingMode:
# class IntervalCollision:
# class WhitespaceCollision:
# class EraseCollision:
# class DuplicateNames:
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __eq__(self, other):
#     def __ne__(self, other):


# Path: praatio/utilities/utils.py
import os
import subprocess
import itertools
import wave
from pkg_resources import resource_filename
from typing_extensions import Literal
from typing import Any, Iterator, List, Tuple, NoReturn, Type
from praatio.utilities import errors
from praatio.utilities import constants

    """
    indexList = []
    index = 0
    while True:
        try:
            index = txt.index(subStr, index)
        except ValueError:
            break
        indexList.append(int(index))
        index += 1

    return indexList


def runPraatScript(
    praatEXE: str, scriptFN: str, argList: List[Any], cwd: str = None
) -> None:

    # Popen gives a not-very-transparent error
    if not os.path.exists(praatEXE):
        raise errors.FileNotFound(praatEXE)
    if not os.path.exists(scriptFN):
        raise errors.FileNotFound(scriptFN)

    argList = ["%s" % arg for arg in argList]
    cmdList = [praatEXE, "--run", scriptFN] + argList

    myProcess = subprocess.Popen(cmdList, cwd=cwd)

    if myProcess.wait():

        raise errors.PraatExecutionFailed(cmdList)