SPPAS 4.20

Module sppas.src.annotations

Class sppasIntsint

Description

SPPAS integration of the INTSINT automatic annotation.

Constructor

Create a new instance.

Parameters
  • log: (sppasLog) Human-readable logs.
View Source
def __init__(self, log=None):
    """Create a new instance.

    :param log: (sppasLog) Human-readable logs.

    """
    super(sppasIntsint, self).__init__('intsint.json', log)
    self.__intsint = Intsint()

Public functions

tier_to_anchors

Initialize INTSINT attributes from a Tier with anchors.

Parameters
  • momel_tier: (sppasTier) A PointTier with float values.
Returns
  • List of tuples(time, f0 value)
View Source
@staticmethod
def tier_to_anchors(momel_tier):
    """Initialize INTSINT attributes from a Tier with anchors.

        :param momel_tier: (sppasTier) A PointTier with float values.
        :returns: List of tuples (time, f0 value)

        """
    targets = list()
    for ann in momel_tier:
        tag = ann.get_best_tag(label_idx=0)
        try:
            f0 = float(tag.get_content())
        except TypeError:
            raise AnnDataTypeError(tag, 'float')
        except ValueError:
            raise AnnDataTypeError(tag, 'float')
        try:
            time = float(ann.get_highest_localization().get_midpoint())
        except TypeError:
            raise AnnDataTypeError(ann.get_highest_localization(), 'float')
        except ValueError:
            raise AnnDataTypeError(ann.get_highest_localization(), 'float')
        targets.append((time, f0))
    return targets
tones_to_tier

Convert the INTSINT result into a tier.

Parameters
  • tones: (list)
  • anchors_tier: (sppasTier)
View Source
@staticmethod
def tones_to_tier(tones, anchors_tier):
    """Convert the INTSINT result into a tier.

        :param tones: (list)
        :param anchors_tier: (sppasTier)

        """
    if len(tones) != len(anchors_tier):
        raise AnnDataEqError('tones:' + str(len(tones)), 'anchors:' + str(len(anchors_tier)))
    tier = sppasTier('INTSINT')
    for tone, anchor_ann in zip(tones, anchors_tier):
        tag = sppasTag(tone)
        location = anchor_ann.get_location().copy()
        tier.create_annotation(location, sppasLabel(tag))
    return tier
get_input_tier

Return the tier with Momel anchors.

Parameters
  • input_files: (list)
Raises

NoTierInputError

Returns
  • (sppasTier) Tier of type Point
View Source
def get_input_tier(self, input_files):
    """Return the tier with Momel anchors.

        :param input_files: (list)
        :raise: NoTierInputError
        :return: (sppasTier) Tier of type Point

        """
    tier = None
    for filename in input_files:
        parser = sppasTrsRW(filename)
        print(filename)
        trs_input = parser.read()
        for t in trs_input:
            print(t.get_name())
        if tier is None:
            tier = sppasFindTier.pitch_anchors(trs_input)
        if tier is None:
            tier = sppasFindTier.pitch(trs_input)
        if tier is not None:
            break
    if tier is None:
        logging.error('Tier with Momel anchors not found.')
        raise NoTierInputError
    if tier.is_point() is False:
        logging.error('The tier with Momel anchors should be of type: Point.')
        raise AnnDataTypeError(tier.get_name(), 'PointTier')
    return tier
run

Run the automatic annotation process on an input.

Parameters
  • input_files: (list of str) momel anchors
  • output: (str) the output file name
Returns
  • (sppasTranscription)
View Source
def run(self, input_files, output=None):
    """Run the automatic annotation process on an input.

        :param input_files: (list of str) momel anchors
        :param output: (str) the output file name
        :returns: (sppasTranscription)

        """
    tier_input = self.get_input_tier(input_files)
    targets = sppasIntsint.tier_to_anchors(tier_input)
    tones = self.__intsint.annotate(targets)
    tier_intsint = sppasIntsint.tones_to_tier(tones, tier_input)
    trs_output = sppasTranscription(self.name)
    trs_output.set_meta('annotation_result_of', input_files[0])
    trs_output.append(tier_intsint)
    if output is not None:
        output_file = self.fix_out_file_ext(output)
        parser = sppasTrsRW(output_file)
        parser.write(trs_output)
        return [output_file]
    return trs_output
get_output_pattern

Pattern this annotation uses in an output filename.

View Source
def get_output_pattern(self):
    """Pattern this annotation uses in an output filename."""
    return self._options.get('outputpattern', '-intsint')
get_input_extensions

Extensions that the annotation expects for its input filename.

INTSINT requires momel anchors which can either be stored in

a TextGrid file or in a PitchTier file.

Returns
  • (list of list)
View Source
@staticmethod
def get_input_extensions():
    """Extensions that the annotation expects for its input filename.

        INTSINT requires momel anchors which can either be stored in
        a TextGrid file or in a PitchTier file.

        :return: (list of list)

        """
    return [sppasFiles.get_informat_extensions('ANNOT')]