Пример #1
0
 def compute(self, x):
     startstopsilence = es.StartStopSilence(threshold=-70)
     for frame in es.FrameGenerator(x, frameSize=2048, hopSize=512, 
                                    startFromZero=True):
         result = startstopsilence(esarray(frame))
     solution = np.array([result[0], result[1]])
     return solution * 512 / 44100.
Пример #2
0
 def compute(self, x):
     startstopsilence = es.StartStopSilence(threshold=-70)
     for frame in es.FrameGenerator(x,
                                    frameSize=2048,
                                    hopSize=512,
                                    startFromZero=True):
         result = startstopsilence(esarray(frame))
     solution = np.array([result[0], result[1]])
     return solution * 512 / 44100.
Пример #3
0
    def compute(self, *args):
        x = args[1]
        LPC = es.LPC(order=order, type='regular')
        W = es.Windowing(size=frame_size, zeroPhase=False, type='triangular')
        predicted = np.zeros(hop_size)
        y = []
        self.frames = []
        self.errors = []
        self.errors_filt = []
        self.samples_peaking_frame = []
        self.frame_idx = []
        self.power = []
        frame_counter = 0

        for frame in es.FrameGenerator(x, frameSize=frame_size,
                                       hopSize=hop_size,
                                       startFromZero=True):
            self.power.append(es.essentia.instantPower(frame))
            self.frames.append(frame)
            frame_un = np.array(frame[hop_size // 2: hop_size * 3 // 2])
            frame = W(frame)
            norm = np.max(np.abs(frame))
            if not norm:
                continue
            frame /= norm

            lpc_f, _ = LPC(esarray(frame))

            lpc_f1 = lpc_f[1:][::-1]

            for idx, i in enumerate(range(hop_size // 2, hop_size * 3 // 2)):
                predicted[idx] = - np.sum(np.multiply(frame[i - order:i], lpc_f1))

            error = np.abs(frame[hop_size // 2: hop_size * 3 // 2] - predicted)

            threshold1 = times_thld * np.std(error)

            med_filter = medfilt(error, kernel_size=kernel_size)
            filtered = np.abs(med_filter - error)

            mask = []
            for i in range(0, len(error), sub_frame):
                r = es.essentia.instantPower(frame_un[i:i + sub_frame]) > energy_thld
                mask += [r] * sub_frame
            mask = mask[:len(error)]
            mask = np.array([mask]).astype(float)[0]

            if sum(mask) == 0:
                threshold2 = 1000  # just skip silent frames
            else:
                threshold2 = times_thld * (np.std(error[mask.astype(bool)]) +
                                           np.median(error[mask.astype(bool)]))

            threshold = np.max([threshold1, threshold2])

            samples_peaking = np.sum(filtered >= threshold)
            if samples_peaking >= 1:
                y.append(frame_counter * hop_size / 44100.)
                self.frame_idx.append(frame_counter)

            self.frames.append(frame)
            self.errors.append(error)
            self.errors_filt.append(filtered)
            self.samples_peaking_frame.append(samples_peaking)

            frame_counter += 1

        return np.array(y)
Пример #4
0
    def compute(self, *args):
        x = args[1]
        LPC = es.LPC(order=order, type='regular')
        W = es.Windowing(size=frame_size, zeroPhase=False, type='triangular')
        predicted = np.zeros(hop_size)
        y = []
        self.frames = []
        self.errors = []
        self.errors_filt = []
        self.samples_peaking_frame = []
        self.frame_idx = []
        self.power = []
        frame_counter = 0

        for frame in es.FrameGenerator(x,
                                       frameSize=frame_size,
                                       hopSize=hop_size,
                                       startFromZero=True):
            self.power.append(es.essentia.instantPower(frame))
            self.frames.append(frame)
            frame_un = np.array(frame[hop_size // 2:hop_size * 3 // 2])
            frame = W(frame)
            norm = np.max(np.abs(frame))
            if not norm:
                continue
            frame /= norm

            lpc_f, _ = LPC(esarray(frame))

            lpc_f1 = lpc_f[1:][::-1]

            for idx, i in enumerate(range(hop_size // 2, hop_size * 3 // 2)):
                predicted[idx] = -np.sum(
                    np.multiply(frame[i - order:i], lpc_f1))

            error = np.abs(frame[hop_size // 2:hop_size * 3 // 2] - predicted)

            threshold1 = times_thld * np.std(error)

            med_filter = medfilt(error, kernel_size=kernel_size)
            filtered = np.abs(med_filter - error)

            mask = []
            for i in range(0, len(error), sub_frame):
                r = es.essentia.instantPower(
                    frame_un[i:i + sub_frame]) > energy_thld
                mask += [r] * sub_frame
            mask = mask[:len(error)]
            mask = np.array([mask]).astype(float)[0]

            if sum(mask) == 0:
                threshold2 = 1000  # just skip silent frames
            else:
                threshold2 = times_thld * (np.std(error[mask.astype(bool)]) +
                                           np.median(error[mask.astype(bool)]))

            threshold = np.max([threshold1, threshold2])

            samples_peaking = np.sum(filtered >= threshold)
            if samples_peaking >= 1:
                y.append(frame_counter * hop_size / 44100.)
                self.frame_idx.append(frame_counter)

            self.frames.append(frame)
            self.errors.append(error)
            self.errors_filt.append(filtered)
            self.samples_peaking_frame.append(samples_peaking)

            frame_counter += 1

        return np.array(y)