Beispiel #1
0
    def __init__(self, logfile=None):
        """

        """
        sppasBase.__init__(self, logfile)

        self.intsint = Intsint()
Beispiel #2
0
class sppasIntsint( sppasBase ):
    """
    @author:       Brigitte Bigi
    @organization: Laboratoire Parole et Langage, Aix-en-Provence, France
    @contact:      [email protected]
    @license:      GPL, v3
    @copyright:    Copyright (C) 2011-2016  Brigitte Bigi
    @summary:      SPPAS integration of the INTSINT automatic annotation.

    """
    def __init__(self, logfile=None):
        """

        """
        sppasBase.__init__(self, logfile)

        self.intsint = Intsint()


    # -----------------------------------------------------------------------
    # Methods to annotate
    # -----------------------------------------------------------------------

    def targets_from_tier(self, momeltier):
        """
        Initialize INTSINT attributes from momel Tier.

        """
        targets = []
        for target in momeltier:
            f0 = float( target.GetLabel().GetValue() )
            targets.append( (target.GetLocation().GetPointMidpoint(),f0) )

        return targets

    # -------------------------------------------------------------------

    def tones_to_tier(self, toneslist, momeltier):
        """
        Convert the INTSINT result into a tier.

        """
        intsinttier = momeltier.Copy()
        intsinttier.SetName("INTSINT")

        for tone,target in zip(toneslist,intsinttier):
            target.GetLabel().SetValue( tone )

        return intsinttier

    # -------------------------------------------------------------------

    def get_input_tier(self, trsinput):
        """
        Return the tier to estimate INTSINT.

        @param trsinput (Transcription)
        @return Tier

        """
        tierinput = None
        for tier in trsinput:
            if "momel" in tier.GetName().lower():
                tierinput = tier
                break

        return tierinput

    # -----------------------------------------------------------------------

    def run( self, inputfilename, outputfile ):
        """
        Run the INTSINT annotation process on an input file.

        @param inputfilename (str - IN) the input file name with momel
        @param outputfile (str - IN) the output file name of the INTSINT tier

        """
        # Get the tier to be annotated.
        trsinput = annotationdata.io.read( inputfilename )
        tierinput = self.get_input_tier(trsinput)
        if tierinput is None:
            raise Exception("No tier found with momel. "
                            "One of the tier names must contain 'momel'.")

        # Annotate the tier
        targets = self.targets_from_tier( tierinput )
        toneslist = self.intsint.annotate( targets )
        tierintsint = self.tones_to_tier( toneslist, tierinput )

        # Save
        trsoutput = Transcription("sppasIntsint")
        trsoutput.Append( tierintsint )

        # Save in a file
        annotationdata.io.write( outputfile,trsoutput )