Auto-CS 2.0

https://sourceforge.net/projects/autocs/

Module CuedSpeech.wherecue

Class sppasWhereCuePredictor

Description

Create a tier indicating the position of 2 points of the hand.

Predict the position of points S0 and S9 of an hand relatively to sights of a face.

Constructor

Create a new instance.

Parameters
  • cue_rules: (CuedSpeechKeys) Rules and codes for vowel positions and hand shapes
View Source
def __init__(self, pos_predictor_version: int=WhereVowelPositionsPredictor.DEFAULT_VERSION, angle_predictor_version: int=WhereAnglesPredictor.DEFAULT_VERSION, cue_rules: CuedSpeechCueingRules=CuedSpeechCueingRules()):
    """Create a new instance.

    :param cue_rules: (CuedSpeechKeys) Rules and codes for vowel positions and hand shapes

    """
    if isinstance(cue_rules, CuedSpeechCueingRules) is False:
        raise sppasTypeError('cue_rules', 'CuedSpeechCueingRules')
    self.__fps = 50
    self.__pos_predictor = sppasWherePositionsPredictor(pos_predictor_version)
    self.__angle_predictor = sppasWhereAnglesPredictor(angle_predictor_version)
    self.__cued = None
    self.__gentargets = TargetProbabilitiesEstimator()
    self.set_cue_rules(cue_rules)

Public functions

get_wherepositionpredictor_versions

Return the list of version numbers of the vowel positions generator system.

View Source
def get_wherepositionpredictor_versions(self) -> list:
    """Return the list of version numbers of the vowel positions generator system."""
    return self.__pos_predictor.version_numbers()

get_whereanglepredictor_versions

Return the list of version numbers of the angles generation system.

View Source
def get_whereanglepredictor_versions(self) -> list:
    """Return the list of version numbers of the angles generation system."""
    return self.__angle_predictor.version_numbers()

get_wherepositionpredictor_version

Return the version number of the vowel positions prediction system.

View Source
def get_wherepositionpredictor_version(self) -> int:
    """Return the version number of the vowel positions prediction system."""
    return self.__pos_predictor.get_version_number()

get_whereanglepredictor_version

Return the version number of the angle prediction system.

View Source
def get_whereanglepredictor_version(self) -> int:
    """Return the version number of the angle prediction system."""
    return self.__angle_predictor.get_version_number()

set_wherepositionpredictor_version

Change the vowel position predictor version number.

Parameters
  • version_number: (int) One of the supported versions.
Raises
  • sppasKeyError: if invalid version number
View Source
def set_wherepositionpredictor_version(self, version_number: int) -> None:
    """Change the vowel position predictor version number.

        :param version_number: (int) One of the supported versions.
        :raises: sppasKeyError: if invalid version number

        """
    self.__pos_predictor.set_version_number(version_number)

set_whereanglepredictor_version

Change the angle predictor version number.

Parameters
  • version_number: (int) One of the supported versions.
Raises
  • sppasKeyError: if invalid version number
View Source
def set_whereanglepredictor_version(self, version_number: int) -> None:
    """Change the angle predictor version number.

        :param version_number: (int) One of the supported versions.
        :raises: sppasKeyError: if invalid version number

        """
    self.__angle_predictor.set_version_number(version_number)

set_cue_rules

Set new rules.

Parameters
  • cue_rules: (CuedSpeechCueingRules) Rules and codes for vowel positions and hand shapes
Raises
  • sppasTypeError: given parameter is not CuedSpeechCueingRules
View Source
def set_cue_rules(self, cue_rules: CuedSpeechCueingRules) -> None:
    """Set new rules.

        :param cue_rules: (CuedSpeechCueingRules) Rules and codes for vowel positions and hand shapes
        :raises: sppasTypeError: given parameter is not CuedSpeechCueingRules

        """
    if isinstance(cue_rules, CuedSpeechCueingRules) is False:
        raise sppasTypeError('cue_rules', 'CuedSpeechCueingRules')
    self.__cued = cue_rules
    self.__gentargets.set_cue_rules(cue_rules)

get_angle_use_face

Return True if the hand angle must be corrected by the one of the face.

View Source
def get_angle_use_face(self) -> bool:
    """Return True if the hand angle must be corrected by the one of the face."""
    return self.__angle_predictor.get_use_face()

set_angle_use_face

The angle of the hand is corrected by the one of the face or not.

Parameters
  • value: (bool) True if the angle of the hand has to be corrected.
View Source
def set_angle_use_face(self, value: bool) -> None:
    """The angle of the hand is corrected by the one of the face or not.

        :param value: (bool) True if the angle of the hand has to be corrected.

        """
    self.__angle_predictor.set_use_face(value)

predict_where

Prodict where to cue, hand angle and hand size from face sights.

Parameters
  • file_sights: (str) Filename with 68 sights of a face for each image of a video
  • tierpostransitions: (sppasTier) Predicted hand position transitions
  • tiershapestransitions: (sppasTier) Predicted hand shapes transitions
Returns
  • (sppasTranscription)
View Source
def predict_where(self, file_sights, tier_pos_transitions, tier_shapes_transitions):
    """Prodict where to cue, hand angle and hand size from face sights.

        :param file_sights: (str) Filename with 68 sights of a face for each image of a video
        :param tier_pos_transitions: (sppasTier) Predicted hand position transitions
        :param tier_shapes_transitions: (sppasTier) Predicted hand shapes transitions
        :return: (sppasTranscription)

        """
    face_sights = self._load_sights(file_sights, kid_index=0)
    self.__set_fps(face_sights)
    tier_sizes = sppasFaceHeightGenerator(face_sights).face_height(fps=self.__fps)
    self.__pos_predictor.set_sights(face_sights)
    tier_pos_coords = self.__pos_predictor.vowels_coords(self.__cued.get_vowels_codes(), smooth_len=self.__fps // 5)
    tier_pos_probas = self.__gentargets.positions_discretization(tier_pos_coords, tier_pos_transitions)
    tier_shp_probas = self.__gentargets.shapes_discretization(tier_pos_coords, tier_shapes_transitions)
    tier_target_coords = self.__gentargets.hands_to_target_coords(tier_pos_probas, tier_pos_coords)
    tier_angles = self.__angle_predictor.hand_angles(tier_pos_probas, face_sights)
    trs = sppasTranscription('WhereToCue')
    trs.append(tier_pos_coords)
    trs.append(tier_shp_probas)
    trs.append(tier_pos_probas)
    trs.append(tier_angles)
    trs.append(tier_sizes)
    trs.append(tier_target_coords)
    return trs

Private functions

_load_sights

Load a filename and store the sights of a given kid.

The returned data is a list of tuples with:

  • at index 0: midpoint time value
  • at index 1: radius time value
  • at index 2: the 68 sights of a face
Parameters
  • filename: (str) Filename of the XRA/CSV with sights
  • kid_index: (int) index of the kid to get sights
Raises
  • sppasWhereCuedSightsValueError: there are sights but there are not of the expected size
  • Exception
Returns
  • (list)
View Source
def _load_sights(self, filename: str, kid_index: int=0) -> list:
    """Load a filename and store the sights of a given kid.

        The returned data is a list of tuples with:

        - at index 0: midpoint time value
        - at index 1: radius time value
        - at index 2: the 68 sights of a face

        :param filename: (str) Filename of the XRA/CSV with sights
        :param kid_index: (int) index of the kid to get sights
        :raises: sppasWhereCuedSightsValueError: there are sights but there are not of the expected size
        :raises: Exception:
        :return: (list)

        """
    data = sppasSightsVideoReader(filename)
    cur_sights = self.__get_current_sights(data, kid_index)
    data_sights = list()
    for (i, kids_sights) in enumerate(data.sights):
        midpoint = data.midpoints[i]
        if midpoint is None:
            raise Exception('No time point value at index {:d}.'.format(i))
        if 0 < len(kids_sights) <= kid_index + 1:
            s = kids_sights[kid_index]
            if s is not None:
                cur_sights = s
            else:
                logging.warning('No estimated sights at frame number {:d} for kid {:d}.'.format(i + 1, kid_index))
        else:
            logging.warning('No estimated sights at frame number {:d} for kid {:d}.'.format(i + 1, kid_index))
        data_sights.append((midpoint, data.radius[i], cur_sights))
    return data_sights

Protected functions

__set_fps

Fix the video frames-per-seconds value.

Parameters
  • data_sights
View Source
def __set_fps(self, data_sights: list) -> None:
    """Fix the video frames-per-seconds value."""
    if len(data_sights) == 0:
        self.__fps = 50
    else:
        first_midpoint = data_sights[0][0]
        self.__fps = int(1.0 / first_midpoint)
        logging.debug(f'Video fps={self.__fps}')

__get_current_sights

Return the sights at given index.

Parameters
  • data: (sppasSightsVideoReader) Video reader with sights
  • kid_index: (int) index of the kid to get sights
Raises
  • sppasWhereCuedSightsValueError: there are sights but there are not of the expected size
  • Exception
View Source
def __get_current_sights(self, data: sppasSightsVideoReader, kid_index: int) -> sppasSights:
    """Return the sights at given index.

        :param data: (sppasSightsVideoReader) Video reader with sights
        :param kid_index: (int) index of the kid to get sights
        :raises: sppasWhereCuedSightsValueError: there are sights but there are not of the expected size
        :raises: Exception:

        """
    cur_sights = sppasSights()
    for (i, kids_sights) in enumerate(data.sights):
        if 0 < len(kids_sights) <= kid_index + 1:
            cur_sights = kids_sights[kid_index]
            if cur_sights is not None:
                break
    return cur_sights