Esempio n. 1
0
def main():
    name = 't20'
    in_dir = './bin/'
    out_dir = './bin/results'
    audio, fs = fileutils.load_audio(name, audio_dir=in_dir)
    # audio_labels = fileutils.load_labels(name, label_dir=in_dir)
    # Should be sensitive to the length of the track, as well as k
    # Perhaps length should be extended as song goes longer than 30 seconds;
    # 3 second = 30 seconds, 18 seconds = 3 min
    # length = tune_length_with_audio(audio, fs)
    length = cfg.SEGMENT_LENGTH

    # explots.draw_results_reference(audio, fs, audio_labels, name=name,
    #                show_plot=('motif',))
    # segmentation_analysis(audio, fs, length, num_motifs=3, name=name,
    #                         show_plot=('arc',))
    # k_means_analysis(audio, fs, length, name=name, k_clusters=(5, 25, 50),
    #                  show_plot=('motif',))
    thresh = 11
    audio_sample = audio
    results, G_set = threshold_analysis(audio_sample,
                                        fs,
                                        length,
                                        name=name,
                                        show_plot=('motif', 'matrix'),
                                        threshold=thresh)
    write_motifs(audio_sample, fs, name, out_dir, results[thresh])

    visutils.show()
    return
Esempio n. 2
0
def main():
    name = 't3_train'
    directory = "./bin/labelled"
    audio, fs = fileutils.load_audio(name, audio_dir=directory)
    audio_labels = fileutils.load_labels(name, label_dir=directory)

    # audio_hashes, audio_pairs, _ = shazam.fingerprint(audio)
    # _, matches, segments = thumbnail_shazam(audio, fs, audio_pairs)
    # ax = vis.plot_similarity_curve(matches, segments, labels=audio_labels)
    # ax.set_title('Similarity Curve for {}'.format(name))

    thumb, similarity, segments, sim_matrix = thumbnail(audio,
                                                        fs,
                                                        seg_method='onset',
                                                        length=2)

    ax = vis.plot_similarity_matrix(sim_matrix)
    ax.set_title('Regular Segmentation Similarity Matrix')
    ax = vis.plot_similarity_curve(similarity,
                                   segment_times=segments,
                                   labels=audio_labels)
    ax.set_title('Regular Segmentation Similarity')
    ax.legend()
    # ax = vis.plot_window_overlap(segments, np.ones(segments.shape) * 2, tick_step=3)
    # ax.set_title('Regular Segmentation Overlap')
    # ax.grid()
    vis.show()

    return
Esempio n. 3
0
def main():
    name = 'genre_test_3'
    directory = "./bin/labelled"
    audio, fs = fileutils.load_audio(name, audio_dir=directory)
    pairs_hash, pairs, peaks = fingerprint(audio)

    sxx = stft(audio,
               n_fft=cfg.WINDOW_SIZE,
               win_length=cfg.WINDOW_SIZE,
               hop_length=int(cfg.WINDOW_SIZE * cfg.OVERLAP_RATIO),
               window='hann')
    sxx = np.abs(sxx)
    sxx = 10 * np.log10(sxx)
    sxx[sxx == -np.inf] = 0  # replace infs with zeros

    seg_hash_one, _, _ = fingerprint(audio[0 * fs:3 * fs])
    seg_hash_two, _, _ = fingerprint(audio[0 * fs:3 * fs])
    print(hash_search(seg_hash_one, seg_hash_two))

    vis.plot_stft(sxx, fs=fs, frames=False)
    vis.plot_peaks(peaks)
    vis.plot_pairs(peaks, pairs)
    vis.plot_stft_with_pairs(sxx, peaks, pairs)
    vis.show()
    return None
Esempio n. 4
0
def main():
    name = 'Avril'
    in_dir = "./bin/test"
    out_dir = "./bin/results"
    segmentation_experiment(name,
                            in_dir,
                            out_dir,
                            show_plot=('group', ),
                            write_motifs=False)
    k_means_experiment(name,
                       in_dir,
                       out_dir,
                       show_plot=('group', ),
                       write_motifs=False)
    similarity_experiment(name,
                          in_dir,
                          out_dir,
                          show_plot=('group', ),
                          write_motifs=False)
    clustering_experiment(name,
                          in_dir,
                          out_dir,
                          show_plot=('group', ),
                          write_motifs=False)
    vis.show()
    return
Esempio n. 5
0
def draw_results_chord(G, name, title_hook, draw_ref=False):
    chord_labels = graph.to_node_dataframe(G)
    c = vis.plot_chordgraph(G,
                            node_data=chord_labels,
                            label_col=cfg.NODE_LABEL,
                            title='Chord Graph for {} {}'.format(
                                name, title_hook),
                            node_color=cfg.CLUSTER_NAME,
                            edge_color=cfg.CLUSTER_EDGE_NAME)
    vis.show(c)

    if draw_ref:
        c = vis.plot_chordgraph(G,
                                node_data=chord_labels,
                                label_col=cfg.NODE_LABEL,
                                title='Chord Graph for {}'.format(name))
        vis.show(c)
Esempio n. 6
0
def main():
    # Run example with regular segmentation
    name = 't1'
    directory = "./bin/test"
    audio, fs = fileutils.load_audio(name, audio_dir=directory)
    audio_labels = fileutils.load_labels(name, label_dir=directory)

    thumb, similarity, segments, sim_matrix = thumbnail(audio, fs,
                                                        seg_method='regular',
                                                        length=2)

    ax = vis.plot_similarity_matrix(sim_matrix)
    ax.set_title('Regular Segmentation Similarity Matrix')
    ax = vis.plot_similarity_curve(similarity, segment_times=segments, labels=audio_labels)
    ax.set_title('Regular Segmentation Similarity')
    ax.legend()
    vis.show()
Esempio n. 7
0
def draw_matrix_arc_chord_demo(G, name, with_chord=False):
    fig = vis.get_fig()
    fig.suptitle('Self-Similarity Visualizations')

    ax = draw_super_axis(fig)
    ax.tick_params(labelcolor='w',
                   top=False,
                   bottom=True,
                   left=False,
                   right=False)

    ax = fig.add_subplot(1, 2, 1)
    adjacency = graph.graph_to_adjacency_matrix(G)
    ax, _ = vis.plot_matrix(adjacency, ax=ax)
    ax.set_xlabel('Time Windows')
    ax.set_ylabel('Time Windows')
    ax.set_title('Self-Similarity Matrix')

    ax = fig.add_subplot(1, 2, 2)
    arc_labels = graph.to_node_dict(G, node_attr=cfg.NODE_LABEL)
    ax = vis.plot_arcgraph(G,
                           node_size=20.,
                           node_color='k',
                           node_labels=arc_labels,
                           font_size=20,
                           ax=ax,
                           vertical_shift=2)
    ax.set_xlabel("Time Segments")
    ax.set_title('Arc Diagram')

    if with_chord:
        chord_labels = graph.to_node_dataframe(G)
        c = vis.plot_chordgraph(G,
                                node_data=chord_labels,
                                label_col=cfg.NODE_LABEL,
                                title='Chord Graph Visualization')
        vis.show(c)
    return fig
Esempio n. 8
0
def main():
    name = 'Repeat'
    in_dir = './bin/test'
    audio, fs = fileutils.load_audio(name, audio_dir=in_dir)
    length = cfg.SEGMENT_LENGTH
    #
    # fig = draw_segmentation_evolution(audio, fs)
    # vis.save_fig(fig, './bin/graphs/', 'SEG_{audio_name}'.format(audio_name=name))
    #
    # thresh = 0.95
    thresh = 0.985
    starts, ends, labels, G = analyzer.analyze(audio,
                                               fs,
                                               seg_length=length,
                                               threshold=thresh,
                                               seg_method='beat')
    #
    # fig = vis.get_fig()
    # fig.suptitle('Arc Graph Clustering')
    # ax = draw_super_axis(fig)
    # ax = draw_simple_arc(G, with_labels=True, with_color=True, ax=ax)
    # vis.save_fig(fig, './bin/graphs/', 'ARC_{audio_name}_clustered'.format(audio_name=name))

    fig = draw_matrix_arc_chord_demo(G, name, with_chord=False)
    vis.save_fig(fig, './bin/graphs/',
                 'SSM2ARC_{audio_name}'.format(audio_name=name))
    #
    # name = 't3'
    # in_dir = './bin/test'
    # audio, fs = fileutils.load_audio(name, audio_dir=in_dir)
    #
    # fig = draw_matrix_evolution(audio, fs, length, name)
    # vis.save_fig(fig, './bin/graphs/', 'SSM_{audio_name}'.format(audio_name=name))

    # results = {}
    # methods = ('With Clustering', 'With Join')
    #
    # name = 'Avril'
    # in_dir = "./bin/test"
    # audio, fs = fileutils.load_audio(name, audio_dir=in_dir)
    # length = cfg.SEGMENT_LENGTH
    #
    # audio_labels = fileutils.load_labels(name, label_dir=in_dir)
    # ref_starts, ref_ends, ref_labels = motif.df_to_motif(audio_labels)
    # fig = vis.get_fig()
    # ax = fig.add_subplot(1, 1, 1)
    # ax = vis.plot_motif_segmentation(audio, fs, ref_starts, ref_ends, ref_labels, ax=ax)
    # fig.suptitle('Hand-Labelled Description of {}'.format(name))
    # vis.save_fig(fig, './bin/graphs/', 'IDEAL_{audio_name}'.format(audio_name=name))

    # starts, ends, labels, G = analyzer.analyze(audio, fs, seg_length=length, with_join=False)
    # this_result = motif.pack_motif(starts, ends, labels)
    # results['With Merging'] = this_result
    #
    # starts, ends, labels, G = analyzer.analyze(audio, fs, seg_length=length, with_join=True)
    # this_result = motif.pack_motif(starts, ends, labels)
    # results['With Join'] = this_result
    #
    # fig = draw_motif_group(audio, fs, results, methods=methods, title='Joining Motif Segments', subplots=(2, 1))
    # vis.save_fig(fig, './bin/graphs/', 'MOTIF_{audio_name}'.format(audio_name=name))

    # name = 't1'
    # in_dir = "./bin/"
    # audio, fs = fileutils.load_audio(name, audio_dir=in_dir)
    # pairs_hash, pairs, peaks = shazam.fingerprint(audio)
    #
    # sxx = shazam.stft(audio,
    #                   n_fft=cfg.WINDOW_SIZE,
    #                   win_length=cfg.WINDOW_SIZE,
    #                   hop_length=int(cfg.WINDOW_SIZE * cfg.OVERLAP_RATIO),
    #                   window='hann')
    # sxx = np.abs(sxx)
    #
    # fig = vis.get_fig()
    # ax = fig.add_subplot(1, 1, 1)
    # ax = vis.plot_stft_with_pairs(sxx, peaks, pairs, ax=ax)
    # fig.suptitle('Spectrogram With Peaks and Pairs')
    #
    # vis.save_fig(fig, './bin/graphs/', 'SHAZAM_{audio_name}'.format(audio_name=name))

    vis.show()

    return