def processFile(self,engine,filename):
        """
            Extract features from the given file using the given engine.
            
            If an output format has been set, then output files will be written, else
            output feature data can be read using engine's :py:meth:`Engine.readOutput`
            or :py:meth:`Engine.readAllOutputs` methods. 

            :param engine: engine to use for feature extraction. It must already have been configured.
            :type engine: :py:class:`Engine`
            :param filename: audio file to process
            :type filename: string
            :return: 0 on success, negative value on fail
        """
        if not AudioFileProcessor._YAAFE_IO_LOADED:
            AudioFileProcessor._YAAFE_IO_LOADED = (loadComponentLibrary('yaafe-io')==0)
        return yc.audiofileprocessor_processFile(self.ptr,engine.ptr,filename)
Beispiel #2
0
 def __new__(mcs, name, base, kdict):
     # check class attributes
     if not 'PARAMS' in kdict:
         kdict['PARAMS'] = []
     if not 'TRANSFORM' in kdict:
         kdict['TRANSFORM'] = False
     # load component libraries
     if 'COMPONENT_LIBS' in kdict:
         for lib in kdict['COMPONENT_LIBS']:
             if yaafecore.loadComponentLibrary(lib) != 0:
                 return
     # compute exposed parameters and check components
     exposed_params = []
     components_available = True
     for p in kdict['PARAMS']:
         if not type(p) == tuple or not len(p) in [2, 3]:
             print 'ERROR: invalid PARAMS attribute for feature %s !' % name
             return None
         if len(p) == 3:
             # explicit parameter
             exposed_params.append(p)
         else:
             params = []
             if isinstance(p[0], AudioFeatureFactory):
                 if not AudioFeatureFactory.feature_available(p[0]):
                     components_available = False
                 # import parameters from a feature
                 params = p[0].get_parameters()
             else:
                 # import parameters from a component
                 if yaafecore.isComponentAvailable(p[0]):
                     params = yaafecore.getComponentParameters(p[0])
                 else:
                     components_available = False
             # override defaults
             params = [(key, p[1].get(key, value), desc)
                       for (key, value, desc) in params
                       if p[1].get(key, True)]
             exposed_params.extend(params)
     exposed_params.sort(cmp=lambda x, y: cmp(x[0], y[0]))
     kdict['_EXPOSED_PARAM_DESCRIPTORS'] = exposed_params
     kdict['_COMPONENTS_AVAILABLE'] = components_available
     # list all params
     kdict['_ALL_PARAMS'] = [key for (key, default, desc) in exposed_params]
     # create class
     return type.__new__(mcs, name, base, kdict)
 def __new__(mcs, name, base, kdict):
     # check class attributes
     if not "PARAMS" in kdict:
         kdict["PARAMS"] = []
     if not "TRANSFORM" in kdict:
         kdict["TRANSFORM"] = False
     # load component libraries
     if "COMPONENT_LIBS" in kdict:
         for lib in kdict["COMPONENT_LIBS"]:
             if yaafecore.loadComponentLibrary(lib) != 0:
                 return
     # compute exposed parameters and check components
     exposed_params = []
     components_available = True
     for p in kdict["PARAMS"]:
         if not type(p) == tuple or not len(p) in [2, 3]:
             print "ERROR: invalid PARAMS attribute for feature %s !" % name
             return None
         if len(p) == 3:
             # explicit parameter
             exposed_params.append(p)
         else:
             params = []
             if isinstance(p[0], AudioFeatureFactory):
                 if not AudioFeatureFactory.feature_available(p[0]):
                     components_available = False
                 # import parameters from a feature
                 params = p[0].get_parameters()
             else:
                 # import parameters from a component
                 if yaafecore.isComponentAvailable(p[0]):
                     params = yaafecore.getComponentParameters(p[0])
                 else:
                     components_available = False
             # override defaults
             params = [(key, p[1].get(key, value), desc) for (key, value, desc) in params if p[1].get(key, True)]
             exposed_params.extend(params)
     exposed_params.sort(cmp=lambda x, y: cmp(x[0], y[0]))
     kdict["_EXPOSED_PARAM_DESCRIPTORS"] = exposed_params
     kdict["_COMPONENTS_AVAILABLE"] = components_available
     # list all params
     kdict["_ALL_PARAMS"] = [key for (key, default, desc) in exposed_params]
     # create class
     return type.__new__(mcs, name, base, kdict)
    def processFile(self, engine, filename):
        """
            Extract features from the given file using the given engine.
            
            If an output format has been set, then output files will be written, else
            output feature data can be read using engine's :py:meth:`Engine.readOutput`
            or :py:meth:`Engine.readAllOutputs` methods. 

            :param engine: engine to use for feature extraction. It must already have been configured.
            :type engine: :py:class:`Engine`
            :param filename: audio file to process
            :type filename: string
            :return: 0 on success, negative value on fail
        """
        if not AudioFileProcessor._YAAFE_IO_LOADED:
            AudioFileProcessor._YAAFE_IO_LOADED = (
                loadComponentLibrary('yaafe-io') == 0)
        return yc.audiofileprocessor_processFile(self.ptr, engine.ptr,
                                                 filename)
Beispiel #5
0
    def setOutputFormat(self, format, outDir, params):
        """
            Set output format.

            :param format: format to set
            :type format: string
            :param outDir: base output directory for output files
            :type outDir: string
            :param params: format parameters
            :type params: dict
            :return: True if ok, False if format does not exists.
        """
        if not AudioFileProcessor._YAAFE_IO_LOADED:
            AudioFileProcessor._YAAFE_IO_LOADED = (
                loadComponentLibrary('yaafe-io') == 0)

        tmp = ((c_char_p*2)*(len(params)+1))()
        tmp[:-1] = [(c_char_p*2)(c_char_p(k), c_char_p(v))
                    for k, v in params.iteritems()]
        if yc.audiofileprocessor_setOutputFormat(self.ptr, format,
                                                 outDir, tmp):
            return True
        return False