Example #1
0
from annotations.Repetitions.detectrepetition  import Repetitions



# ----------------------------------------------------------------------------
# Verify and extract args:
# ----------------------------------------------------------------------------

parser = ArgumentParser(usage="%s -i file [options]" % os.path.basename(PROGRAM), description="Self- and Other- repetitions detection command line interface.")

parser.add_argument("-i", metavar="file", required=True, help='Input file name with time-aligned tokens of the self-speaker')

parser.add_argument("-r", metavar="file",  help='Either the lemma dictionary or the list of stop-words')
parser.add_argument("-I", metavar="file",  help='Input file name with time-aligned tokens of the echoing-speaker (if ORs)')
parser.add_argument("-o", metavar="file",  help='Output file name')

if len(sys.argv) <= 1:
    sys.argv.append('-h')

args = parser.parse_args()


# ----------------------------------------------------------------------------
# Automatic detection is here:
# ----------------------------------------------------------------------------

p = sppasRepetition( args.r )
p.run( args.i, args.I, args.o )

# ----------------------------------------------------------------------------
Example #2
0
    def run_repetition(self, stepidx):
        """
        Execute the automatic repetitions detection.

        """
        # Initializations
        step = self.parameters.get_step(stepidx)
        stepname = self.parameters.get_step_name(stepidx)
        files_processed_success = 0
        self._progress.set_header(stepname)
        self._progress.update(0,"")

        # Get the list of input file names, with the ".wav" (or ".wave") extension
        filelist = self.set_filelist(".wav",not_start=["track_"])
        if len(filelist) == 0:
            return 0
        total = len(filelist)

        # Create annotation instance
        try:
            self._progress.set_text("Loading resources...")
            r = sppasRepetition( step.get_langresource(), self._logfile )
        except Exception as e:
            if self._logfile is not None:
                self._logfile.print_message( "%s\n"%str(e), indent=1,status=1 )
            return 0

        for i,f in enumerate(filelist):

            # fix the default values
            r.fix_options( step.get_options() )

            # Indicate the file to be processed
            self._progress.set_text( os.path.basename(f)+" ("+str(i+1)+"/"+str(total)+")" )
            if self._logfile is not None:
                self._logfile.print_message(stepname+" of file " + f, indent=1 )

            # Get the input file
            ext = ['-palign'+self.parameters.get_output_format()]
            for e in annotationdata.io.extensions_out_multitiers:
                ext.append( '-palign'+e )

            inname = self._get_filename(f, ext)
            if inname is not None:

                # Fix output file name
                outname = os.path.splitext(f)[0] + '-ralign' + self.parameters.get_output_format()

                # Execute annotation
                try:
                    r.run( inname, outputfilename=outname )
                except Exception as e:
                    if self._logfile is not None:
                        self._logfile.print_message( "%s for file %s\n"%(str(e),outname), indent=2,status=-1 )
                else:
                    files_processed_success += 1
                    if self._logfile is not None:
                        self._logfile.print_message(outname, indent=2,status=0 )
            else:
                if self._logfile is not None:
                    self._logfile.print_message("Failed to find a file with time-aligned tokens. Read the documentation for details.",indent=2,status=2)

            # Indicate progress
            self._progress.set_fraction(float((i+1))/float(total))
            if self._logfile is not None:
                self._logfile.print_newline()

        # Indicate completed!
        self._progress.update(1,"Completed (%d files successfully over %d files).\n"%(files_processed_success,total))
        self._progress.set_header("")

        return files_processed_success