def perform_command(self):
        """
        Perform command and return the appropriate exit code.

        :rtype: int
        """
        if len(self.actual_arguments) < 2:
            return self.print_help()
        input_file_path = self.actual_arguments[0]
        output_file_path = self.actual_arguments[1]

        output_text_format = self.has_option_with_value(u"--format")
        if output_text_format is None:
            output_text_format = u"%.18e"
        output_binary = self.has_option([u"-b", u"--binary"])
        output_npz = self.has_option([u"-z", u"--npz"])
        output_npy = self.has_option([u"-n", u"--npy"])
        delete_first = self.has_option([u"-d", u"--delete-first"])
        transpose = self.has_option([u"-t", u"--transpose"])

        self.check_c_extensions("cmfcc")
        if not self.check_input_file(input_file_path):
            return self.ERROR_EXIT_CODE
        if not self.check_output_file(output_file_path):
            return self.ERROR_EXIT_CODE

        try:
            mfccs = AudioFileMFCC(input_file_path, rconf=self.rconf, logger=self.logger).all_mfcc
            if delete_first:
                mfccs = mfccs[1:, :]
            if transpose:
                mfccs = mfccs.transpose()
            if output_binary:
                # save as a raw C float64 binary file
                mapped = numpy.memmap(output_file_path, dtype="float64", mode="w+", shape=mfccs.shape)
                mapped[:] = mfccs[:]
                mapped.flush()
                del mapped
            elif output_npz:
                # save as a .npz compressed binary file
                with io.open(output_file_path, "wb") as output_file:
                    numpy.savez(output_file, mfccs)
            elif output_npy:
                # save as a .npy binary file
                with io.open(output_file_path, "wb") as output_file:
                    numpy.save(output_file, mfccs)
            else:
                # save as a text file
                # NOTE: in Python 2, passing the fmt value a Unicode string crashes NumPy
                #       hence, converting back to bytes, which works in Python 3 too
                numpy.savetxt(output_file_path, mfccs, fmt=gf.safe_bytes(output_text_format))
            self.print_info(u"MFCCs shape: %d %d" % (mfccs.shape))
            self.print_success(u"MFCCs saved to '%s'" % (output_file_path))
            return self.NO_ERROR_EXIT_CODE
        except AudioFileConverterError:
            self.print_error(u"Unable to call the ffmpeg executable '%s'" % (self.rconf[RuntimeConfiguration.FFMPEG_PATH]))
            self.print_error(u"Make sure the path to ffmpeg is correct")
        except (AudioFileUnsupportedFormatError, AudioFileNotInitializedError):
            self.print_error(u"Cannot read file '%s'" % (input_file_path))
            self.print_error(u"Check that its format is supported by ffmpeg")
        except OSError:
            self.print_error(u"Cannot write file '%s'" % (output_file_path))

        return self.ERROR_EXIT_CODE
def perform_command ( self ) : if len ( self . actual_arguments ) < 2 : return self . print_help ( ) input_file_path = self . actual_arguments [ 0 ] output_file_path = self . actual_arguments [ 1 ] output_text_format = self . has_option_with_value ( u"--format" ) if output_text_format is None : output_text_format = u"%.18e" output_binary = self . has_option ( [ u"-b" , u"--binary" ] ) output_npz = self . has_option ( [ u"-z" , u"--npz" ] ) output_npy = self . has_option ( [ u"-n" , u"--npy" ] ) delete_first = self . has_option ( [ u"-d" , u"--delete-first" ] ) transpose = self . has_option ( [ u"-t" , u"--transpose" ] ) self . check_c_extensions ( "cmfcc" ) if not self . check_input_file ( input_file_path ) : return self . ERROR_EXIT_CODE if not self . check_output_file ( output_file_path ) : return self . ERROR_EXIT_CODE try : mfccs = AudioFileMFCC ( input_file_path , rconf = self . rconf , logger = self . logger ) . all_mfcc if delete_first : mfccs = mfccs [ 1 : , : ] if transpose : mfccs = mfccs . transpose ( ) if output_binary : mapped = numpy . memmap ( output_file_path , dtype = "float64" , mode = "w+" , shape = mfccs . shape ) mapped [ : ] = mfccs [ : ] mapped . flush ( ) del mapped elif output_npz : with io . open ( output_file_path , "wb" ) as output_file : numpy . savez ( output_file , mfccs ) elif output_npy : with io . open ( output_file_path , "wb" ) as output_file : numpy . save ( output_file , mfccs ) else : numpy . savetxt ( output_file_path , mfccs , fmt = gf . safe_bytes ( output_text_format ) ) self . print_info ( u"MFCCs shape: %d %d" % ( mfccs . shape ) ) self . print_success ( u"MFCCs saved to '%s'" % ( output_file_path ) ) return self . NO_ERROR_EXIT_CODE except AudioFileConverterError : self . print_error ( u"Unable to call the ffmpeg executable '%s'" % ( self . rconf [ RuntimeConfiguration . FFMPEG_PATH ] ) ) self . print_error ( u"Make sure the path to ffmpeg is correct" ) except ( AudioFileUnsupportedFormatError , AudioFileNotInitializedError ) : self . print_error ( u"Cannot read file '%s'" % ( input_file_path ) ) self . print_error ( u"Check that its format is supported by ffmpeg" ) except OSError : self . print_error ( u"Cannot write file '%s'" % ( output_file_path ) ) return self . ERROR_EXIT_CODE
Perform command and return the appropriate exit code.

        :rtype: int