Пример #1
0
    def getInputs(self):
        """
            Get input metadata. Result format is the same as for
            :py:meth:`getOutputs` method, but the general case is
            that there is only one input named 'audio' and the sole
            relevant metadata are:

            :sampleRate: expected audio sampleRate
            :parameters: attached parameters

            Others fields should be set to 1.
        """
        res = {}
        iList = yc.engine_getInputList(self.ptr)
        for inputname in iterPtrList(iList):
            ptr = yc.engine_getInputInfos(self.ptr, to_char(inputname))
            infos = {}
            if ptr:
                infos['sampleRate'] = ptr.contents.sampleRate
                infos['sampleStep'] = ptr.contents.sampleStep
                infos['frameLength'] = ptr.contents.frameLength
                infos['size'] = ptr.contents.size
                infos['parameters'] = dict(
                    (to_str(k), to_str(v))
                    for k, v in iterPtrDict(ptr.contents.parameters))
                yc.engine_freeIOInfos(ptr)
            res[to_str(inputname)] = infos
        yc.engine_freeIOList(iList)
        return res
Пример #2
0
def getComponentParameters(name):
    ptr = yaafecore.getComponentParameters(to_char(name))
    res = [(to_str(p.contents.identifier),
            to_str(p.contents.defaultValue),
            to_str(p.contents.description)) for p in iterPtrList(ptr)]
    yaafecore.freeComponentParameters(ptr)
    return res
Пример #3
0
    def getOutputs(self):
        """
            Get output metadata. For each output feature, you get the following
            metadata:

            :sampleRate: audio analysis samplerate
            :sampleStep: Number of audio samples between consecutive feature
                         values
            :frameLength: Analysis frame size in number of audio samples
            :size: size the feature (or number of coefficients)
            :parameters: attached parameters.
        """
        res = {}
        oList = yc.engine_getOutputList(self.ptr)
        for outputname in iterPtrList(oList):
            ptr = yc.engine_getOutputInfos(self.ptr, to_char(outputname))
            infos = {}
            if ptr:
                infos['sampleRate'] = ptr.contents.sampleRate
                infos['sampleStep'] = ptr.contents.sampleStep
                infos['frameLength'] = ptr.contents.frameLength
                infos['size'] = ptr.contents.size
                infos['parameters'] = dict(
                    (to_str(k), to_str(v))
                    for k, v in iterPtrDict(ptr.contents.parameters))
                yc.engine_freeIOInfos(ptr)
            res[to_str(outputname)] = infos
        yc.engine_freeIOList(oList)
        return res
Пример #4
0
    def dumpdot(self, filename):
        """
            write a got graph corresponding to the DataFlow

            :param filename: file to write
            :type filename: string
        """
        yc.dataflow_dumpdot(self.ptr, to_char(filename))
Пример #5
0
    def dumpdot(self, filename):
        """
            write a got graph corresponding to the DataFlow

            :param filename: file to write
            :type filename: string
        """
        yc.dataflow_dumpdot(self.ptr, to_char(filename))
Пример #6
0
    def save(self, filename):
        """
            write DataFlow into a :ref:`dataflow file <dataflow-file>`.

            :param filename: file to write
            :type filename: string
        """
        yc.dataflow_save(self.ptr, to_char(filename))
Пример #7
0
    def save(self, filename):
        """
            write DataFlow into a :ref:`dataflow file <dataflow-file>`.

            :param filename: file to write
            :type filename: string
        """
        yc.dataflow_save(self.ptr, to_char(filename))
Пример #8
0
    def readOutput(self, name):
        """
            Read a specific output, and returns values as a numpy.array

            :param name: output name to read
            :type name: string
            :rtype: numpy.array
        """
        import numpy as np
        size = c_int(0)
        tokens = c_int(0)
        yc.engine_output_available(self.ptr, to_char(name), pointer(size),
                                   pointer(tokens))
        if tokens == 0:
            return None
        data = np.zeros((tokens.value, size.value))
        yc.engine_output_read(self.ptr, to_char(name), data, data.shape[1],
                              data.shape[0])
        return data
Пример #9
0
    def load(self, filename):
        """
            Build DataFlow from a :ref:`dataflow file <dataflow-file>`.

            :param filename: dataflow file name.
            :type filename: string
            :return: True on success, False on fail.
        """
        if yc.dataflow_load(self.ptr, to_char(filename)):
            self.update_state()
            return True
        return False
Пример #10
0
    def load(self, filename):
        """
            Build DataFlow from a :ref:`dataflow file <dataflow-file>`.

            :param filename: dataflow file name.
            :type filename: string
            :return: True on success, False on fail.
        """
        if yc.dataflow_load(self.ptr, to_char(filename)):
            self.update_state()
            return True
        return False
Пример #11
0
    def loads(self, buf):
        """
            Build DataFlow from buf read from a :ref:`dataflow file
            <dataflow-file>`.

            :param buf: buffer read from a dataflow file
            :type buf: string
            :return: True on success, False on fail.
        """
        if yc.dataflow_loads(self.ptr, to_char(buf)):
            self.update_state()
            return True
        return False
Пример #12
0
    def loads(self, buf):
        """
            Build DataFlow from buf read from a :ref:`dataflow file
            <dataflow-file>`.

            :param buf: buffer read from a dataflow file
            :type buf: string
            :return: True on success, False on fail.
        """
        if yc.dataflow_loads(self.ptr, to_char(buf)):
            self.update_state()
            return True
        return False
Пример #13
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(to_char(k)), c_char_p(to_char(v)))
                    for k, v in iteritems(params)]
        if yc.audiofileprocessor_setOutputFormat(self.ptr, to_char(format),
                                                 to_char(outDir), tmp):
            return True
        return False
Пример #14
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(to_char(k)), c_char_p(to_char(v)))
                    for k, v in iteritems(params)]
        if yc.audiofileprocessor_setOutputFormat(self.ptr, to_char(format),
                                                 to_char(outDir), tmp):
            return True
        return False
Пример #15
0
def readH5FeatureDescriptions(filename):
    out = yaafecore.readH5FeatureDescriptions(to_char(filename))
    res = {}
    if out:
        for featDesc in iterPtrList(out):
            resFeat = {}
            resFeat['dim'] = featDesc.contents.dim
            resFeat['nbframes'] = featDesc.contents.nbframes
            resFeat['sampleRate'] = featDesc.contents.sampleRate
            resFeat['blockSize'] = featDesc.contents.blockSize
            resFeat['stepSize'] = featDesc.contents.stepSize
            resFeat['attrs'] = dict((k, v) for k, v
                                    in iterPtrDict(featDesc.contents.attrs))
            res[featDesc.contents.name] = resFeat
    yaafecore.freeH5FeatureDescriptions(out)
    return res
Пример #16
0
    def writeInput(self, name, data):
        """
            Write data on an input.

            :param name: input on which to write
            :type name: string
            :param data: data to write.
            :type data: numpy array

        """
        size = 1
        toks = len(data)
        if (len(data.shape) == 2):
            size = data.shape[0]
            toks = data.shape[1]
        elif (len(data.shape) > 2):
            print('ERROR: data must be a 1-d or 2-d array !')
            return
        yc.engine_input_write(self.ptr, to_char(name), data, size, toks)
Пример #17
0
    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,
                                                 to_char(filename))
Пример #18
0
    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,
                                                 to_char(filename))
Пример #19
0
def getOutputFormatParameters(name):
    ptr = yaafecore.getOutputFormatParameters(to_char(name))
    res = [(p.contents.identifier, p.contents.defaultValue,
            p.contents.description) for p in iterPtrList(ptr)]
    yaafecore.freeComponentParameters(ptr)
    return res
Пример #20
0
 def createNode(self, componentId, params):
     tmp = ((c_char_p * 2) * (len(params) + 1))()
     tmp[:-1] = [(c_char_p * 2)(c_char_p(to_char(k)), c_char_p(to_char(v)))
                 for k, v in iteritems(params)]
     return DataFlowNode(
         yc.dataflow_createNode(self.ptr, to_char(componentId), tmp))
Пример #21
0
def getOutputFormatDescription(name):
    ptr = yaafecore.getOutputFormatDescription(to_char(name))
    res = cast(ptr, c_char_p).value
    yaafecore.freeOutputFormatDescription(ptr)
    return res
Пример #22
0
def isComponentAvailable(name):
    return True if yaafecore.isComponentAvailable(to_char(name)) else False
Пример #23
0
def loadComponentLibrary(name):
    return yaafecore.loadComponentLibrary(to_char(name))
Пример #24
0
 def createNode(self, componentId, params):
     tmp = ((c_char_p*2)*(len(params)+1))()
     tmp[:-1] = [(c_char_p*2)(c_char_p(to_char(k)), c_char_p(to_char(v)))
                 for k, v in iteritems(params)]
     return DataFlowNode(yc.dataflow_createNode(self.ptr,
                                                to_char(componentId), tmp))
Пример #25
0
 def getNode(self, name):
     ptr = yc.dataflow_getNode(self.ptr, to_char(name))
     return DataFlowNode(ptr) if ptr else None
Пример #26
0
 def link(self, sourceNode, sourcePort, targetNode, targetPort):
     yc.dataflow_link(self.ptr, sourceNode.ptr, to_char(sourcePort),
                      targetNode.ptr, to_char(targetPort))
Пример #27
0
 def useComponentLibrary(self, libname):
     yc.dataflow_useComponentLibrary(self.ptr, to_char(libname))
Пример #28
0
 def link(self, sourceNode, sourcePort, targetNode, targetPort):
     yc.dataflow_link(self.ptr, sourceNode.ptr, to_char(sourcePort),
                      targetNode.ptr, to_char(targetPort))
Пример #29
0
 def getNode(self, name):
     ptr = yc.dataflow_getNode(self.ptr, to_char(name))
     return DataFlowNode(ptr) if ptr else None
Пример #30
0
 def useComponentLibrary(self, libname):
     yc.dataflow_useComponentLibrary(self.ptr, to_char(libname))
Пример #31
0
 def setNodeName(self, node, name):
     yc.dataflow_setNodeName(self.ptr, node.ptr, to_char(name))
Пример #32
0
 def setNodeName(self, node, name):
     yc.dataflow_setNodeName(self.ptr, node.ptr, to_char(name))