[Python] Can't save image in Ubuntu for Librosa

Discussão em 'Python' iniciado por Stack, Setembro 10, 2024.

  1. Stack

    Stack Membro Participativo

    Below code is fine to operate in jupyter notebook in Windows.

    However, images can't be saved in Jetson Orin Nano in Ubuntu 22.04 LTS.

    I put audio files in "Record" folder.

    I checked there are values for "data_5s_y" and "d_data_5s_y".

    But plt.savefig doesn't save anything.

    Therefore, last line had an error because there aren't any files in "'./Spectrogram/5s/".

    As a result, I highly doubt that there is a problem of saving image.

    import librosa
    import glob
    from PIL import Image
    import os
    import numpy as np
    import matplotlib.pyplot as plt
    import time

    hop_length = 1024
    num = 0
    num_10s = 1

    while True:

    wav_file = glob.glob('./Record/*.wav')

    data_5s_y, data_5s_sr = librosa.load(wav_file[num])

    d_data_5s_y = librosa.amplitude_to_db(np.abs(librosa.stft(data_5s_y, hop_length=hop_length)), ref=np.max)

    librosa.display.specshow(d_data_5s_y, y_axis='log', x_axis='time',
    sr=data_5s_sr, hop_length=hop_length)
    plt.axis('off')

    filename = wav_file[num].split('\\')[-1].split('.')[0]

    plt.savefig('./Spectrogram/5s/%s.png' % filename, bbox_inches='tight', pad_inches=0)

    png_file = glob.glob('./Spectrogram/5s/*.png')

    im = Image.open(png_file[0])

    Continue reading...

Compartilhe esta Página