Auto-CS 2.0

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

Module CuedSpeech.wherecue

Class sppasWherePositionsPredictor

Description

Predict the position of all the vowels from sights in a file.

Create a tier indicating the position of CS vowels.

Constructor

Create a new instance of vowels predictor.

Parameters
  • predictor_version
View Source
def __init__(self, predictor_version=WhereVowelPositionsPredictor.DEFAULT_VERSION):
    """Create a new instance of vowels predictor.

    """
    self.__predictor = WhereVowelPositionsPredictor(predictor_version)
    self.__data_sights = list()

Public functions

version_numbers

Return the whole list of supported version numbers.

View Source
def version_numbers(self) -> list:
    """Return the whole list of supported version numbers."""
    return self.__predictor.version_numbers()

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.__predictor.get_version_number()

set_version_number

Change the predictor version number.

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.

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

        """
    self.__predictor.set_version_number(version_number)

get_nb_sights

Return the number of sights.

View Source
def get_nb_sights(self) -> int:
    """Return the number of sights."""
    return len(self.__data_sights)

set_sights

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

The given 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
  • data_sights: (list) List of sights of a face
Raises
  • TypeError: if data_sights is not a list
  • TypeError: if data_sights is not a list of tuples
  • sppasWhereCuedSightsValueError: there are sights but there are not of the expected size
View Source
def set_sights(self, data_sights: list) -> None:
    """Load a filename and store the sights of a given kid.

        The given 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 data_sights: (list) List of sights of a face
        :raises: TypeError: if data_sights is not a list
        :raises: TypeError: if data_sights is not a list of tuples
        :raises: sppasWhereCuedSightsValueError: there are sights but there are not of the expected size

        """
    if isinstance(data_sights, (list, tuple)) is True:
        for s in data_sights:
            if isinstance(s, (tuple, list)) is False or len(s) != 3:
                raise TypeError('Invalid item in the list of sights: {:s}'.format(str(s)))
            cur_sights = s[2]
            if cur_sights is not None and len(cur_sights) != self.__predictor.get_sights_dim():
                raise sppasWhereCuedSightsValueError(self.__predictor.get_sights_dim(), len(cur_sights))
        self.__data_sights = data_sights
    else:
        raise TypeError('Invalid given sights. Expected a list. Got {:s}'.format(str(type(data_sights))))

vowels_coords

Predict the coordinates of the given vowels.

Notice that the coordinates of the position can have negative values.

The 'smooth_len' variable is used to smooth the coordinates in order to eliminate micro-movements caused by the imprecision in detecting points and facial movements, preventing any visible 'shaking'.

Parameters
  • smooth_len: (int) Length of the queue used to smooth coords.
  • vowels: (None | list) List of the vowel codes to predict.
Returns
  • (sppasTier) tier with name 'CS-VowelsCoords'
View Source
def vowels_coords(self, vowels: list, smooth_len: int=20):
    """Predict the coordinates of the given vowels.

        Notice that the coordinates of the position can have negative values.

        The 'smooth_len' variable is used to smooth the coordinates in order to
        eliminate micro-movements caused by the imprecision in detecting points
        and facial movements, preventing any visible 'shaking'.

        :param smooth_len: (int) Length of the queue used to smooth coords.
        :param vowels: (None | list) List of the vowel codes to predict.
        :return: (sppasTier) tier with name 'CS-VowelsCoords'

        """
    tier = sppasTier('CS-VowelsCoords')
    if vowels is None:
        vowels = self.__predictor.vowel_codes()
    points_x = dict()
    points_y = dict()
    points_r = dict()
    for vowel in vowels:
        points_x[vowel] = deque(maxlen=smooth_len)
        points_y[vowel] = deque(maxlen=smooth_len)
        points_r[vowel] = deque(maxlen=smooth_len)
    for (midpoint, radius, sights) in self.__data_sights:
        self.__predictor.set_sights_and_predict_coords(sights, vowels)
        labels = list()
        for vowel in vowels:
            if vowel in self.__predictor.vowel_codes():
                (x, y, r) = self.__predictor.get_vowel_coords(vowel)
                x = self.__append_and_smooth(points_x[vowel], x)
                y = self.__append_and_smooth(points_y[vowel], y)
                r = self.__append_and_smooth(points_r[vowel], r)
                tag = sppasTag((x, y, r), tag_type='point')
                label = sppasLabel(tag)
                label.set_key(vowel)
                labels.append(label)
        loc = sppasLocation(sppasPoint(midpoint, radius))
        tier.create_annotation(loc, labels)
    return tier

Protected functions

__append_and_smooth

Append into the queue and return the smoothed value.

Parameters
  • deck
  • value
View Source
@staticmethod
def __append_and_smooth(deck: deque, value: int):
    """Append into the queue and return the smoothed value.

        """
    deck.append(value)
    if len(deck) > 1:
        return int(fmean(deck))
    return value