Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
1
Indexable
Never
y = train_dataset[34]['audio']['array']

seccoes = seccionar(y,5e-2)

print("N° seccoes:",len(seccoes))
print("\n\n")

for seccao in seccoes[:5]:

    spec = np.abs(librosa.stft(seccao, n_fft= 512))#, hop_length= 2**6))
    spec = librosa.amplitude_to_db(spec, ref=np.max)

    print(spec.shape)

    plt.figure(figsize = (15,7))
    librosa.display.specshow(spec,  x_axis='time', y_axis='log');
    plt.colorbar(format='%+2.0f dB');
    plt.title('Spectrogram');




novo_img_trainset = []
novo_labels = []
for numero,audio in enumerate(train_dataset):
    
    y = audio['audio']['array']
    label = audio['label']
    
    threshold = np.abs(y).max()/10

    seccoes = seccionar(y,threshold)

    print("audio numero:",numero ," |  N° seccoes:",len(seccoes))
#    print("\n\n")
    for seccao in seccoes:
        
        spec = np.abs(librosa.stft(seccao, n_fft= 512))#, hop_length= 2**6))
        spec = librosa.amplitude_to_db(spec, ref=np.max)
        novo_img_trainset.append(spec)
        novo_labels.append(label)