How to use the librosa.display.specshow function in librosa

To help you get started, we’ve selected a few librosa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github librosa / librosa / tests / test_display.py View on Github external
def test_cqt_note(C):
    plt.figure()
    librosa.display.specshow(C, y_axis='cqt_note')
    return plt.gcf()
github vivjay30 / pychorus / pychorus / similarity_matrix.py View on Github external
def display(self):
        import librosa.display
        import matplotlib.pyplot as plt
        librosa.display.specshow(
            self.matrix,
            y_axis='time',
            x_axis='time',
            sr=self.sample_rate / (N_FFT / 2048))
        plt.colorbar()
        plt.set_cmap("hot_r")
        plt.show()
github makcedward / nlpaug / nlpaug / util / visual / spectrogram.py View on Github external
def visual(title, spectrogram):
        plt.figure(figsize=(8, 4))
        librosa.display.specshow(
            librosa.power_to_db(spectrogram, ref=np.max), y_axis='mel', fmax=8000, x_axis='time')
        plt.colorbar(format='%+10.0f dB')
        plt.title(title)
        plt.tight_layout()
        plt.show()
github dpwe / audfprint / audfprint_match.py View on Github external
d, sr = audio_read.audio_read(filename, sr=analyzer.target_sr, channels=1)
        sgram = np.abs(stft.stft(d, n_fft=analyzer.n_fft,
                                 hop_length=analyzer.n_hop,
                                 window=np.hanning(analyzer.n_fft + 2)[1:-1]))
        sgram = 20.0 * np.log10(np.maximum(sgram, np.max(sgram) / 1e6))
        sgram = sgram - np.mean(sgram)
        # High-pass filter onset emphasis
        # [:-1,] discards top bin (nyquist) of sgram so bins fit in 8 bits
        # spectrogram enhancement
        if self.illustrate_hpf:
            HPF_POLE = 0.98
            sgram = np.array([scipy.signal.lfilter([1, -1],
                                                   [1, -HPF_POLE], s_row)
                              for s_row in sgram])[:-1, ]
        sgram = sgram - np.max(sgram)
        librosa.display.specshow(sgram, sr=sr, hop_length=analyzer.n_hop,
                                 y_axis='linear', x_axis='time',
                                 cmap='gray_r', vmin=-80.0, vmax=0)
        # Do the match?
        q_hashes = analyzer.wavfile2hashes(filename)
        # Run query, get back the hashes for match zero
        results, matchhashes = self.match_hashes(ht, q_hashes, hashesfor=0)
        if self.sort_by_time:
            results = sorted(results, key=lambda x: -x[2])
        # Convert the hashes to landmarks
        lms = audfprint_analyze.hashes2landmarks(q_hashes)
        mlms = audfprint_analyze.hashes2landmarks(matchhashes)
        # Overplot on the spectrogram
        time_scale = analyzer.n_hop / float(sr)
        freq_scale = float(sr)/analyzer.n_fft
        plt.plot(time_scale * np.array([[x[0], x[0] + x[3]] for x in lms]).T,
                 freq_scale * np.array([[x[1], x[2]] for x in lms]).T,
github GianlucaPaolocci / Sound-classification-on-Raspberry-Pi-with-Tensorflow / urbanMLP.py View on Github external
def plot_log_power_specgram(sound_names,raw_sounds):
    i = 1
    fig = plt.figure(figsize=(25,60), dpi = 900)
    for n,f in zip(sound_names,raw_sounds):
        plt.subplot(10,1,i)
        D = librosa.logamplitude(np.abs(librosa.stft(f))**2, ref_power=np.max)
        librosa.display.specshow(D,x_axis='time' ,y_axis='log')
        plt.title(n.title())
        i += 1
    plt.suptitle('Figure 3: Log power spectrogram',x=0.5, y=0.915,fontsize=18)
    plt.show()
github foamliu / Speech-Transformer / specAugment / spec_augment_pytorch.py View on Github external
def visualization_spectrogram(mel_spectrogram, title):
    """visualizing result of specAugment
    # Arguments:
      mel_spectrogram(ndarray): mel_spectrogram to visualize.
      title(String): plot figure's title
    """
    # Show mel-spectrogram using librosa's specshow.
    plt.figure(figsize=(10, 4))
    librosa.display.specshow(librosa.power_to_db(mel_spectrogram[0, :, :], ref=np.max), y_axis='mel', fmax=8000,
                             x_axis='time')
    # plt.colorbar(format='%+2.0f dB')
    plt.title(title)
    plt.tight_layout()
    plt.show()
github ycemsubakan / sourceseparation_misc / gan_things.py View on Github external
def drawgendata_atomic():
        I = 1
        N = 2 
        
        genspec = out_g.data.numpy().transpose()[:, :200]
        target = tar[0].numpy().transpose()[:, :200]

        #genspec = out_g[].data.numpy().transpose()
        #target = tar.permute(0,2,1).contiguous().view(-1, L2).numpy().transpose()
        for i in range(I):
                        
            plt.subplot(N, I, i+1)
            lrd.specshow(genspec, y_axis='log', x_axis='time') 
            
            plt.subplot(N, I, i+2) 
            lrd.specshow(target, y_axis='log', x_axis='time')
github mdangschat / ctc-asr / asr / dataset / audio_sample_info.py View on Github external
# Calculating MEL spectrogram and MFCC.
    db_pow = np.abs(
        librosa.stft(y=y, n_fft=n_fft, hop_length=hop_length, win_length=win_length)) ** 2

    s_mel = librosa.feature.melspectrogram(S=db_pow, sr=sr, hop_length=hop_length,
                                           fmax=f_max, fmin=f_min, n_mels=n_mels)

    s_mel = librosa.power_to_db(s_mel, ref=np.max)
    s_mfcc = librosa.feature.mfcc(S=s_mel, sr=sr, n_mfcc=n_mfcc)

    # STFT (Short-time Fourier Transform)
    # https://librosa.github.io/librosa/generated/librosa.core.stft.html
    plt.figure(figsize=(12, 10))
    db = librosa.amplitude_to_db(librosa.magphase(librosa.stft(y))[0], ref=np.max)
    plt.subplot(3, 2, 1)
    display.specshow(db, sr=sr, x_axis='time', y_axis='linear', hop_length=hop_length)
    plt.colorbar(format='%+2.0f dB')
    plt.title('Linear-frequency power spectrogram')

    plt.subplot(3, 2, 2)
    display.specshow(db, sr=sr, x_axis='time', y_axis='log', hop_length=hop_length)
    plt.colorbar(format='%+2.0f dB')
    plt.title('Log-frequency power spectrogram')

    plt.subplot(3, 2, 3)
    display.specshow(s_mfcc, sr=sr, x_axis='time', y_axis='linear', hop_length=hop_length)
    plt.colorbar(format='%+2.0f dB')
    plt.title('MFCC spectrogram')

    # # CQT (Constant-T Transform)
    # # https://librosa.github.io/librosa/generated/librosa.core.cqt.html
    cqt = librosa.amplitude_to_db(librosa.magphase(librosa.cqt(y, sr=sr))[0], ref=np.max)
github ycemsubakan / sourceseparation_misc / gan_things.py View on Github external
#genspec = out_g[].data.numpy().transpose()
        #target = tar.permute(0,2,1).contiguous().view(-1, L2).numpy().transpose()

        for i in range(I):
            plt.subplot(N, I, i+1)
            plt.imshow(genspec) 
            
            plt.subplot(N, I, I+i+1) 
            plt.imshow(target)
            
            plt.subplot(N, I, I+i+2)
            lrd.specshow(genspec, y_axis='log', x_axis='time') 
            
            plt.subplot(N, I, I+i+3) 
            lrd.specshow(target, y_axis='log', x_axis='time')

            plt.subplot(N, I, I+i+4) 
            lrd.specshow(feat, y_axis='log', x_axis='time')
github CorentinJ / Real-Time-Voice-Cloning / sv2tts / encoder / ui / speaker_matrix_ui.py View on Github external
def _plot_partial_utterance(self, partial_utterance):
        figure = Figure()
        canvas = FigureCanvas(figure)
        
        # Load the partial utterance"s frames and waveform
        utterance, frames, frames_range = partial_utterance
        wave_fpath = utterance.wave_fpath
        wave = audio.load(wave_fpath)
        wave = audio.preprocess_wave(wave)
        
        wave_range = np.array(frames_range) * sampling_rate * (mel_window_step / 1000)
        wave = wave[int(wave_range[0]):int(wave_range[1])]
    
        # Plot the spectrogram and the waveform
        ax = figure.add_subplot(211)
        librosa.display.specshow(
            librosa.power_to_db(frames.transpose(), ref=np.max),
            hop_length=int(sampling_rate * 0.01),
            y_axis="mel",
            x_axis="time",
            sr=sampling_rate,
            ax=ax
        )
        ax.get_xaxis().set_visible(False)
        ax = figure.add_subplot(212, sharex=ax)
        librosa.display.waveplot(
            wave,
            sr=sampling_rate,
            ax=ax
        )
        figure.tight_layout()
        canvas.draw()