Example #1
0
def calculate_cluster_distance(sample, database):
    distances = list()
    sample_feature_vector = MFCC.voice_feature_extraction(sample)
    for database_sample in os.listdir(database):
        database_feature_vector = MFCC.voice_feature_extraction(
            os.path.join(database, database_sample))
        distances.append(
            DTW.dynamic_time_warping(sample_feature_vector,
                                     database_feature_vector))

    return np.mean(distances)
def calculate_within_cluster_distance(filepath):
    feature_vectors = list()
    samples = os.listdir(filepath)
    for sample in samples:
        feature_vectors.append(
            MFCC.voice_feature_extraction(os.path.join(filepath, sample)))

    distances = list()
    for i in range(0, len(feature_vectors)):
        for j in range(i + 1, len(feature_vectors)):
            distances.append(
                DTW.dynamic_time_warping(feature_vectors[i],
                                         feature_vectors[j]))

    return np.max(distances)