예제 #1
0
def cluster(src, key="AvgTonalCentroid(6)", nbins=15, min_volume=-30):
    jsonfile = "%s-%s-%d.json" % (src, key, nbins)
    if os.path.exists(jsonfile):
        return deserialize(jsonfile)

    analysis = meap.analysis(src)

    segs = []
    features = []
    rms = []

    for idx, X in enumerate(analysis):
        segs.append((X["onset_time"], X["chunk_length"], idx))
        features.append(X[key])
        rms.append(X["RMSAmplitude(1)"])

    rms = np.array(rms)
    features = np.array(features)
    segs = np.array(segs)

    too_quiet = rms < min_volume

    quiet_segs = segs[too_quiet]

    features = features[np.invert(too_quiet)]
    segs = segs[np.invert(too_quiet)]

    codebook, distortion = kmeans(features, nbins)

    clusters, distance = vq(features, codebook)

    out = {}
    for i in range(nbins + 1):
        out[i] = []

    for idx, cluster in enumerate(clusters):
        out[cluster].append(segs[idx].tolist())

    out[nbins] = quiet_segs.tolist()

    serialize(out, jsonfile)

    return out
예제 #2
0
파일: cluster.py 프로젝트: stymy/bsides
def cluster(src, key="AvgTonalCentroid(6)", nbins=15, min_volume=-30):
    jsonfile = "%s-%s-%d.json" % (src, key, nbins)
    if os.path.exists(jsonfile):
        return deserialize(jsonfile)

    analysis = meap.analysis(src)

    segs = []
    features = []
    rms = []

    for idx, X in enumerate(analysis):
        segs.append((X["onset_time"], X["chunk_length"], idx))
        features.append(X[key])
        rms.append(X["RMSAmplitude(1)"])

    rms = np.array(rms)
    features = np.array(features)
    segs = np.array(segs)

    too_quiet = rms < min_volume

    quiet_segs = segs[too_quiet]

    features = features[np.invert(too_quiet)]
    segs = segs[np.invert(too_quiet)]

    codebook, distortion = kmeans(features, nbins)

    clusters, distance = vq(features, codebook)

    out = {}
    for i in range(nbins + 1):
        out[i] = []

    for idx, cluster in enumerate(clusters):
        out[cluster].append(segs[idx].tolist())

    out[nbins] = quiet_segs.tolist()

    serialize(out, jsonfile)

    return out
예제 #3
0
파일: compose.py 프로젝트: strob/bsides
 def _get_features(self):
     a = meap.analysis(self.path)
     out = [X[self.key] for X in a]
     return np.array(out)
예제 #4
0
파일: compose.py 프로젝트: strob/bsides
 def _get_segments(self):
     a = meap.analysis(self.path)
     return [Seg(X["onset_time"], X["chunk_length"], idx)
             for idx,X in enumerate(a)]
예제 #5
0
 def _get_features(self):
     a = meap.analysis(self.path)
     out = [X[self.key] for X in a]
     return np.array(out)
예제 #6
0
 def _get_segments(self):
     a = meap.analysis(self.path)
     return [
         Seg(X["onset_time"], X["chunk_length"], idx)
         for idx, X in enumerate(a)
     ]