Public functions
version_numbers
Return the whole list of supported version numbers.
View Source
@staticmethod
def version_numbers() -> list:
"""Return the whole list of supported version numbers."""
return list(WhenTransitionPredictor.HAND_TRANSITIONS.keys())
get_a1a3_avg_duration
Return the average of stored [A1;A3] durations or the fixed one.
If there's not enough known [A1;A3] durations, the fixed value is
returned.
View Source
def get_a1a3_avg_duration(self) -> float:
"""Return the average of stored [A1;A3] durations or the fixed one.
If there's not enough known [A1;A3] durations, the fixed value is
returned.
"""
return self.__predictor.get_a1a3_avg_duration()
get_version_number
Return the version number of the selected predictor (int).
View Source
def get_version_number(self) -> int:
"""Return the version number of the selected predictor (int)."""
return self.__version
set_version_number
Change the predictor version number.
It invalidates the current values of A1 and A3.
Parameters
- version_number: (int) One of the supported versions.
Raises
- sppasKeyError: if invalid version number
View Source
def set_version_number(self, version_number: int) -> None:
"""Change the predictor version number.
It invalidates the current values of A1 and A3.
:param version_number: (int) One of the supported versions.
:raises: sppasKeyError: if invalid version number
"""
authorized = self.version_numbers()
try:
v = int(version_number)
if v not in authorized:
raise sppasKeyError(str(authorized), version_number)
except ValueError:
logging.error('Hand transition: invalid predictor version {}. Expected one of: {}'.format(version_number, authorized))
raise sppasKeyError(str(authorized), version_number)
self.__version = v
self.__predictor = WhenTransitionPredictor.HAND_TRANSITIONS[self.__version]()
set_a
Set [A1,A3] the moments of the sounds of a newly observed key.
Instantiate the predictor with the given interval:
- a1 - when the 1st phoneme of the key starts in the audio;
- a3 - when the 2nd phoneme of the key ends in the audio.
Parameters
- a1: (float) Start time value of a key
- a3: (float) End time value of a key
- store: (bool) Store the a1 and a3 values into a list
Raises
- sppasTypeError: one of a1 or a3 is not a float
- RangeBoundsException: if a3 is lesser than a1
- sppasCuedPredictorError: No predictor system is defined
View Source
def set_a(self, a1: float, a3: float, store: bool=True) -> None:
"""Set [A1,A3] the moments of the sounds of a newly observed key.
Instantiate the predictor with the given interval:
- a1 - when the 1st phoneme of the key starts in the audio;
- a3 - when the 2nd phoneme of the key ends in the audio.
:param a1: (float) Start time value of a key
:param a3: (float) End time value of a key
:param store: (bool) Store the a1 and a3 values into a list
:raises: sppasTypeError: one of a1 or a3 is not a float
:raises: RangeBoundsException: if a3 is lesser than a1
:raises: sppasCuedPredictorError: No predictor system is defined
"""
if self.__predictor is None:
raise sppasCuedPredictorError
self.__predictor.set_key_interval(a1, a3, store)
reset_key_intervals
Forget the stored A1,A3 moments.
View Source
def reset_key_intervals(self):
"""Forget the stored A1,A3 moments."""
self.__predictor.reset_key_intervals()
predict_m
Predict [M1,M2] the moments when the hand is moving.
Make use of the defined predictor and estimates the position
transition moments:
- Predict M1 - when leaving the current position
- Predict M2 - when arrived to the expected position
Neutral means it's not a phoneme: the key is 0-n.
A nil shape means it's a key of type -V.
Depending on the predictor, possible arguments are:
- rank: (int) The rank of the key after a silence (sil=0, 1st key=1, ...)
- isnilshape: (bool) The shape is nil, i.e. there's no consonant in the syllable (N-V)
Returns
- tuple(float, float) The interval [M1,M2] or (0.,0.)
Raises
- sppasCuedPredictorError: No predictor defined.
View Source
def predict_m(self, **kwargs) -> tuple:
"""Predict [M1,M2] the moments when the hand is moving.
Make use of the defined predictor and estimates the position
transition moments:
- Predict M1 - when leaving the current position
- Predict M2 - when arrived to the expected position
Neutral means it's not a phoneme: the key is 0-n.
A nil shape means it's a key of type -V.
Depending on the predictor, possible arguments are:
- rank: (int) The rank of the key after a silence (sil=0, 1st key=1, ...)
- is_nil_shape: (bool) The shape is nil, i.e. there's no consonant in the syllable (N-V)
:return: tuple(float, float) The interval [M1,M2] or (0.,0.)
:raises: sppasCuedPredictorError: No predictor defined.
"""
if self.__predictor is None:
raise sppasCuedPredictorError
return self.__predictor.predict_position(**kwargs)
predict_d
Predict [D1,D2] the moments when fingers are changing.
Make use of the defined predictor and estimates the shape transition
moments:
- Predict D1 - when starting to move fingers
- Predict D2 - when ending to move fingers
Depending on the predictor, possible arguments are:
- rank: (int) The rank of the key after a silence (sil=0, 1st key=1, ...)
- isnilshape: (bool) The shape is nil, i.e. there's no consonant in the syllable (N-V)
Returns
- tuple(float, float) The interval [D1,D2] or (0.,0.)
Raises
- sppasCuedPredictorError: No predictor defined.
View Source
def predict_d(self, **kwargs) -> tuple:
"""Predict [D1,D2] the moments when fingers are changing.
Make use of the defined predictor and estimates the shape transition
moments:
- Predict D1 - when starting to move fingers
- Predict D2 - when ending to move fingers
Depending on the predictor, possible arguments are:
- rank: (int) The rank of the key after a silence (sil=0, 1st key=1, ...)
- is_nil_shape: (bool) The shape is nil, i.e. there's no consonant in the syllable (N-V)
:return: tuple(float, float) The interval [D1,D2] or (0.,0.)
:raises: sppasCuedPredictorError: No predictor defined.
"""
if self.__predictor is None:
raise sppasCuedPredictorError
return self.__predictor.predict_shape(**kwargs)