Beispiel #1
0
    def run_alignment(self, stepidx):
        """
        Execute the SPPAS-Alignment program.

        """
        # 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:
            a = sppasAlign( step.get_langresource(), logfile=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

        # Execute the annotation for each file in the list
        for i,f in enumerate(filelist):

            # fix the default values
            a.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
            extt = ['-token'+self.parameters.get_output_format()]
            extp = ['-phon'+self.parameters.get_output_format()]
            for e in annotationdata.io.extensions_out_multitiers:
                extt.append( '-token'+e )
                extp.append( '-phon'+e )

            inname = self._get_filename(f, extp)
            intok  = self._get_filename(f, extt)
            if inname is not None:

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

                # Execute annotation
                try:
                    a.run( inname, intok, f, outputfilename=outname )
                except Exception as e:
                    if self._logfile is not None:
                        stre = unicode(e.message).encode("utf-8")
                        self._logfile.print_message( "%s for file %s\n"%(stre,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 phonetization. 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
Beispiel #2
0
# ----------------------------------------------------------------------------

parser = ArgumentParser(usage="%s -w file -i file -m file -o file [options]" % os.path.basename(PROGRAM), description="Speech segmentation command line interface.")

parser.add_argument("-w", metavar="file", required=True,  help='Input wav file name')
parser.add_argument("-i", metavar="file", required=True,  help='Input file name with the phonetization')
parser.add_argument("-I", metavar="file", required=False, help='Input file name with the tokenization')
parser.add_argument("-r", metavar="file", required=True,  help='Directory of the acoustic model')
parser.add_argument("-o", metavar="file", required=True,  help='Output file name with estimated alignments')
parser.add_argument("-a", metavar="name", required=False, choices='["julius","hvite","basic"]', default="julius", help='Aligner name. One of: julius, hvite, basic (default: julius)')
parser.add_argument("--extend", action='store_true', help="Extend last phoneme/token to the wav duration" )

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

args = parser.parse_args()


# ----------------------------------------------------------------------------
# Automatic aligment is here:
# ----------------------------------------------------------------------------

a = sppasAlign( args.r )

a.set_aligner( args.a )
if args.extend: a.set_extend( True )

a.run( args.i, args.I, args.w, args.o )

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