コード例 #1
0
def loadFile(path, sr=16000, time=3.0):
    spectrogram = Spectrogram(input_shape=(int(time * sr), 1), sr=sr)
    X = []
    curr = 0  # indicates 1st and last file of speaker
    speaker_dict = {}

    print('Total speakers:', len(os.listdir(path)))
    c = 0

    for speaker in os.listdir(path):
        if c % 10 == 0:
            print('Speakers done:', c)
        c += 1
        print('Loading speaker: ' + speaker)
        speaker_path = os.path.join(path, speaker)
        speaker_dict[speaker] = [curr, None]
        X_speaker = []

        for file_path in os.listdir(speaker_path):
            files = os.path.join(speaker_path, file_path)
            audio, rate = librosa.load(files, sr=sr)
            audio = np.expand_dims(audio, axis=1)

            spec = spectrogram.spectrogram(audio)
            X_speaker.append(spec)
            curr += 1

        speaker_dict[speaker][1] = curr - 1
        X.append(X_speaker)

    return X, speaker_dict
コード例 #2
0
ファイル: trace.py プロジェクト: Zhitaow/code-demo
 def plot_trace(self, spectrogram, trace_info, clim = [0.5, 1.5], color = 'r'):
     ''' plot traced coordinates in the dynamic spectrum
     '''
     
     base0 = Spectrogram()
     base0.spectrogram = spectrogram
     fig0, ax0 = base0.plot_spectrogram(figsize = [12,8], subplot = 211, clim = clim, cmap = 'Greys_r', aspect = 0.2)
     base1 = Spectrogram()
     base1.spectrogram = spectrogram
     fig1, ax1 = base1.plot_spectrogram(fig = fig0, subplot = 212, clim = clim, cmap = 'Greys_r', aspect = 0.2)
     trace_info = self.idx2map(spectrogram, trace_info)
     idplt = trace_info["ID"]
     xplt= trace_info["indy"]
     yplt = trace_info["frequency"]
     # overplot traced drift bursts
     for i in np.arange(idplt.min(), idplt.max()+1):
         idx = np.where(idplt == i)[0]
         if len(idx) > 1:
             plt.plot(xplt[idx],yplt[idx], color = color)
     ylim = ax0.get_ylim()
     ax1.set_ylim(ylim)
     plt.show()
コード例 #3
0
def generate_graphs(directory):
    for file in os.listdir(directory):
        print(directory + file)
        if file.endswith(".dig"):
            # Then we have the right file.

            Spectrogram_Object = Spectrogram(directory + file)
            sampleSize = 256
            full_length_spectra = Spectrogram_Object.spectrogram(
                0, Spectrogram_Object.samples, sampleSize)

            colormaps = ["gist_stern", "tab20c", "tab20b", "terrain"]

            for colormap in colormaps:
                Spectrogram_Object.plot(full_length_spectra,
                                        sample_window=sampleSize,
                                        cmap=colormap)