praatio.utilities.errors
1from typing import List 2 3from praatio.utilities import constants 4 5 6class PraatioException(Exception): 7 pass 8 9 10class SafeZipException(PraatioException): 11 pass 12 13 14class FileNotFound(PraatioException): 15 def __init__(self, fullPath: str): 16 super(FileNotFound, self).__init__() 17 self.fullPath = fullPath 18 19 def __str__(self): 20 return "File not found:\n%s" % self.fullPath 21 22 23class ParsingError(PraatioException): 24 pass 25 26 27class ArgumentError(PraatioException): 28 pass 29 30 31class UnexpectedError(PraatioException): 32 pass 33 34 35class WrongOption(PraatioException): 36 def __init__(self, argumentName: str, givenValue: str, availableOptions: List[str]): 37 self.argumentName = argumentName 38 self.givenValue = givenValue 39 self.availableOptions = availableOptions 40 41 def __str__(self): 42 return ( 43 f"For argument '{self.argumentName}' was given the value '{self.givenValue}'. " 44 f"However, expected one of [{', '.join(self.availableOptions)}]" 45 ) 46 47 48class TextgridException(PraatioException): 49 pass 50 51 52class DuplicateTierName(TextgridException): 53 pass 54 55 56class OutOfBounds(TextgridException): 57 pass 58 59 60class CollisionError(TextgridException): 61 pass 62 63 64class TimelessTextgridTierException(TextgridException): 65 def __str__(self): 66 return "All textgrid tiers much have a min and max duration" 67 68 69# When the state of a textgrid has to change in a way the user did 70# not expect (e.g. a new interval was added that is longer 71# than the maxTimestamp, causing maxTimestamp to be lengthened) 72class TextgridStateAutoModified(TextgridException): 73 pass 74 75 76class TextgridStateError(TextgridException): 77 pass 78 79 80class TierNameExistsError(TextgridException): 81 pass 82 83 84class IncompatibleTierError(TextgridException): 85 def __init__(self, tier): 86 super(IncompatibleTierError, self).__init__() 87 self.tier = tier 88 if self.tier.tierType == constants.INTERVAL_TIER: 89 self.otherTierType = constants.POINT_TIER 90 else: 91 self.otherTierType = constants.INTERVAL_TIER 92 93 def __str__(self): 94 return ( 95 f"Incompatible tier type. Tier with name {self.tier.name} has type" 96 f"{self.tier.tierType} but expected {self.otherTierType}" 97 ) 98 99 100class PraatExecutionFailed(PraatioException): 101 def __init__(self, cmdList: List[str]): 102 super(PraatExecutionFailed, self).__init__() 103 self.cmdList = cmdList 104 105 def __str__(self): 106 errorStr = ( 107 "\nPraat Execution Failed. Please check the following:\n" 108 "- Praat exists in the location specified\n" 109 "- Praat script can execute ok outside of praat\n" 110 "- script arguments are correct\n\n" 111 "If you can't locate the problem, I recommend using " 112 "absolute paths rather than relative " 113 "paths and using paths without spaces in any folder " 114 "or file names\n\n" 115 "Here is the command that python attempted to run:\n" 116 ) 117 cmdTxt = " ".join(self.cmdList) 118 return errorStr + cmdTxt 119 120 121class FindZeroCrossingError(PraatioException): 122 def __init__(self, startTime: float, endTime: float): 123 super(FindZeroCrossingError, self).__init__() 124 125 self.startTime = startTime 126 self.endTime = endTime 127 128 def __str__(self): 129 retString = "No zero crossing found between %f and %f" 130 return retString % (self.startTime, self.endTime) 131 132 133class NormalizationException(PraatioException): 134 def __str__(self): 135 return ( 136 "Local normalization will nullify the effect of global normalization. " 137 "Local normalization should be used to examine local phenomena " 138 "(e.g. max pitch in a segment of running speech)." 139 "Global normalization should be used to examine global phenomena " 140 "(e.g. the pitch range of a speaker)." 141 )
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
15class FileNotFound(PraatioException): 16 def __init__(self, fullPath: str): 17 super(FileNotFound, self).__init__() 18 self.fullPath = fullPath 19 20 def __str__(self): 21 return "File not found:\n%s" % self.fullPath
Common base class for all non-exit exceptions.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
36class WrongOption(PraatioException): 37 def __init__(self, argumentName: str, givenValue: str, availableOptions: List[str]): 38 self.argumentName = argumentName 39 self.givenValue = givenValue 40 self.availableOptions = availableOptions 41 42 def __str__(self): 43 return ( 44 f"For argument '{self.argumentName}' was given the value '{self.givenValue}'. " 45 f"However, expected one of [{', '.join(self.availableOptions)}]" 46 )
Common base class for all non-exit exceptions.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
65class TimelessTextgridTierException(TextgridException): 66 def __str__(self): 67 return "All textgrid tiers much have a min and max duration"
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
85class IncompatibleTierError(TextgridException): 86 def __init__(self, tier): 87 super(IncompatibleTierError, self).__init__() 88 self.tier = tier 89 if self.tier.tierType == constants.INTERVAL_TIER: 90 self.otherTierType = constants.POINT_TIER 91 else: 92 self.otherTierType = constants.INTERVAL_TIER 93 94 def __str__(self): 95 return ( 96 f"Incompatible tier type. Tier with name {self.tier.name} has type" 97 f"{self.tier.tierType} but expected {self.otherTierType}" 98 )
Common base class for all non-exit exceptions.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
101class PraatExecutionFailed(PraatioException): 102 def __init__(self, cmdList: List[str]): 103 super(PraatExecutionFailed, self).__init__() 104 self.cmdList = cmdList 105 106 def __str__(self): 107 errorStr = ( 108 "\nPraat Execution Failed. Please check the following:\n" 109 "- Praat exists in the location specified\n" 110 "- Praat script can execute ok outside of praat\n" 111 "- script arguments are correct\n\n" 112 "If you can't locate the problem, I recommend using " 113 "absolute paths rather than relative " 114 "paths and using paths without spaces in any folder " 115 "or file names\n\n" 116 "Here is the command that python attempted to run:\n" 117 ) 118 cmdTxt = " ".join(self.cmdList) 119 return errorStr + cmdTxt
Common base class for all non-exit exceptions.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
122class FindZeroCrossingError(PraatioException): 123 def __init__(self, startTime: float, endTime: float): 124 super(FindZeroCrossingError, self).__init__() 125 126 self.startTime = startTime 127 self.endTime = endTime 128 129 def __str__(self): 130 retString = "No zero crossing found between %f and %f" 131 return retString % (self.startTime, self.endTime)
Common base class for all non-exit exceptions.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
134class NormalizationException(PraatioException): 135 def __str__(self): 136 return ( 137 "Local normalization will nullify the effect of global normalization. " 138 "Local normalization should be used to examine local phenomena " 139 "(e.g. max pitch in a segment of running speech)." 140 "Global normalization should be used to examine global phenomena " 141 "(e.g. the pitch range of a speaker)." 142 )
Common base class for all non-exit exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args