Beispiel #1
0
    def syllabify_interval(self, phonemes, from_p, to_p, syllables):
        """Perform the syllabification of one interval.

        :param phonemes: (sppasTier)
        :param from_p: (int) index of the first phoneme to be syllabified
        :param to_p: (int) index of the last phoneme to be syllabified
        :param syllables: (sppasTier)

        """
        # create the sequence of phonemes to syllabify
        p = list()
        for ann in phonemes[from_p:to_p + 1]:
            tag = ann.get_best_tag()
            p.append(tag.get_typed_content())

        # create the sequence of syllables
        s = self.__syllabifier.annotate(p)

        # add the syllables into the tier
        for i, syll in enumerate(s):
            start_idx, end_idx = syll

            # create the location
            begin = phonemes[start_idx +
                             from_p].get_lowest_localization().copy()
            end = phonemes[end_idx + from_p].get_highest_localization().copy()
            location = sppasLocation(sppasInterval(begin, end))

            # create the label
            syll_string = Syllabifier.phonetize_syllables(p, [syll])
            label = sppasLabel(sppasTag(syll_string))

            # add the syllable
            syllables.create_annotation(location, label)
Beispiel #2
0
    def __add_repetition(repetition, spk1_tier, spk2_tier, start_idx1,
                         start_idx2, src_tier, echo_tier):
        """Add a repetition - source and echos - in tiers.

        :param repetition: (DataRepetition)
        :param spk1_tier: (Tier) The tier of speaker 1 (to detect sources)
        :param spk2_tier: (Tier) The tier of speaker 2 (to detect echos)
        :param start_idx1: start index of the interval in spk1_tier
        :param start_idx2: start index of the interval in spk2_tier
        :param src_tier: (Tier) The resulting tier with sources
        :param echo_tier: (Tier) The resulting tier with echos
        :returns: (bool) the repetition was added or not

        """
        index = len(src_tier)

        # Source
        s, e = repetition.get_source()
        src_begin = spk1_tier[start_idx1 + s].get_lowest_localization()
        src_end = spk1_tier[start_idx1 + e].get_highest_localization()
        time = sppasInterval(src_begin.copy(), src_end.copy())
        try:
            a = src_tier.create_annotation(
                sppasLocation(time),
                sppasLabel(sppasTag("S" + str(index + 1))))
            src_id = a.get_meta('id')
        except TierAddError:
            return False

        # Echos
        for (s, e) in repetition.get_echos():
            rep_begin = spk2_tier[start_idx2 + s].get_lowest_localization()
            rep_end = spk2_tier[start_idx2 + e].get_highest_localization()
            time = sppasInterval(rep_begin.copy(), rep_end.copy())
            r = sppasLabel(sppasTag("R" + str(index + 1)))
            try:
                a = echo_tier.create_annotation(sppasLocation(time), r)
                a.set_meta('is_other_repetition_of', src_id)
            except TierAddError:
                a = echo_tier.find(rep_begin, rep_end)
                if len(a) > 0:
                    a[0].append_label(r)

        return True
Beispiel #3
0
    def __add_repetition(repetition, spk_tier, start_idx, src_tier, echo_tier):
        """Add a repetition - source and echos - in tiers.

        :param repetition: (DataRepetition)
        :param spk_tier: (sppasTier) The tier of the speaker (to detect sources)
        :param start_idx: (int) start index of the interval in spk_tier
        :param src_tier: (sppasTier) The resulting tier with sources
        :param echo_tier: (sppasTier) The resulting tier with echos
        :returns: (bool) the repetition was added or not

        """
        index = len(src_tier)

        # Source
        s, e = repetition.get_source()
        src_begin = spk_tier[start_idx + s].get_lowest_localization()
        src_end = spk_tier[start_idx + e].get_highest_localization()
        time = sppasInterval(src_begin.copy(), src_end.copy())
        try:
            a = src_tier.create_annotation(
                sppasLocation(time),
                sppasLabel(sppasTag("S" + str(index + 1))))
            src_id = a.get_meta('id')
        except:
            return False

        # Echos
        for (s, e) in repetition.get_echos():
            rep_begin = spk_tier[start_idx + s].get_lowest_localization()
            rep_end = spk_tier[start_idx + e].get_highest_localization()
            time = sppasInterval(rep_begin.copy(), rep_end.copy())
            a = echo_tier.create_annotation(
                sppasLocation(time),
                sppasLabel(sppasTag("R" + str(index + 1))))
            a.set_meta('is_self_repetition_of', src_id)

        return True
    b = (i + start) * delta
    e = b + delta

    for t in tiers_numbers:
        tier = trs_input[t - 1]
        # get only ONE annotation in our range
        anns = tier.find(b, e, overlaps=True)
        if len(anns) > 1:
            anni = tier.near(b + int(delta / 2.), direction=0)
            ann = tier[anni]
        else:
            ann = anns[0]
        texts.append(ann.serialize_labels())

    # Append in new tier
    ti = sppasInterval(sppasPoint(b, 0.0001), sppasPoint(e, 0.0001))
    if len(texts) > 1:
        missing = False
        for t in texts:
            if len(t.strip()) == 0:
                # missing annotation label...
                missing = True
        if missing is True:
            text = ""
        else:
            text = ";".join(texts)
    else:
        text = str(texts[0])
    behavior_tier.create_annotation(sppasLocation(ti),
                                    sppasLabel(sppasTag(text)))
Beispiel #5
0
            for hyp_ann in hyp_tier:
                if hyp_ann in to_merge_anns:
                    anns_to_merge = to_merge_anns[hyp_ann]
                    if anns_to_merge is not None:
                        # a. merge ipus (hyp5)
                        #    ref:     #    |         ipu        |    #
                        #    hyp:     #    | ipu    |  #  | ipu  |   #
                        nb_hyp_merge_ipus += len(anns_to_merge) - 1
                        labels = []
                        for h in anns_to_merge:
                            labels.extend(h.get_labels())
                        labels.append(sppasLabel(sppasTag('Merged')))
                        a = a_hyp_tier.create_annotation(
                            sppasLocation(
                                sppasInterval(
                                    to_merge_anns[hyp_ann][0].get_location().get_best().get_begin(),
                                    to_merge_anns[hyp_ann][-1].get_location().get_best().get_end())),
                            labels
                            )
                else:
                    a_hyp_tier.add(hyp_ann)
        else:
            a_hyp_tier = hyp_tier

        # Communicate the results:
        # ------------------------
        
        trs.append(tier_ref_result)
        logging.info('    ==> Match success is {:d} ({:.2f}%)'
                     ''.format(nb_ref_perfect_match,
                               (float(nb_ref_perfect_match) / float(nb_ipus_ref)) * 100.))
Beispiel #6
0
try:
    trs_input.shift(args.d)
except AnnDataTypeError:
    trs_input.shift(int(args.d))

shifted_trs_start_point = trs_input.get_min_loc().copy()
shifted_trs_end_point = trs_input.get_max_loc().copy()

# ----------------------------------------------------------------------------
# Write

parser.set_filename(args.o)
if sppasRW.create_trs_from_extension(args.o).gaps_support() is False and \
   args.nofill is False:
    for tier in trs_input:
        if tier.is_point():
            continue
        else:
            if args.d > 0:
                tier.create_annotation(
                    sppasLocation(sppasInterval(trs_start_point,
                                  shifted_trs_start_point)))
            elif args.d < 0:
                tier.create_annotation(
                    sppasLocation(sppasInterval(shifted_trs_end_point,
                                                trs_end_point)))

if args.quiet is False:
    print("Write output: {:s}".format(args.o))
parser.write(trs_input)