Oserror: [Errno 30] Read-Only File System: '/Static' on Macos+Visual Code

I have written below code to save spectrograms of uploaded wav file to a specific folder say '/static/images/spectrograms' however, I am getting OSError: [Errno 30] Read-only file system: '/static'. Could someone please suggest how can this be rectified?

def saveMel2(y, directory):

    N_FFT = 1024         # Number of frequency bins for Fast Fourier Transform
    HOP_SIZE = 1024      # Number of audio frames between STFT columns
    SR = 44100           # Sampling frequency
    N_MELS = 30          # Mel band parameters   
    WIN_SIZE = 1024      # number of samples in each STFT window
    WINDOW_TYPE = 'hann' # the windowin function
    FEATURE = 'mel'      # feature representation
    
    spectral_centroids = librosa.feature.spectral_centroid(y=y, sr=sr)[0]
    frames = range(len(spectral_centroids))
    t = librosa.frames_to_time(frames)

    plt.rcParams['figure.figsize'] = (10,2)            
    fig = plt.figure(1,frameon=False)
    DPI = 72
    fig.set_size_inches(224/float(DPI),224/float(DPI))
    ax = plt.Axes(fig, [0., 0., 1., 1.])
    ax.set_axis_off()
    fig.add_axes(ax)
    
    ax1 = plt.subplot(2, 1, 1)
    spectogram = librosa.display.specshow(
             librosa.core.amplitude_to_db(
                librosa.feature.melspectrogram(
                                y=y, 
                                sr=SR)),x_axis='time', y_axis='mel')
    plt.subplot(2, 1, 2, sharex=ax1)
    librosa.display.waveplot(y=y, sr=sr, alpha=0.4)
    plt.plot(t, normalize(spectral_centroids), color='r')
    fig.savefig(directory)
    fig.clear()
    ax.cla()
    plt.clf()
    plt.close('all')

def create_spectrogram(file):
    size = {'desired': 10, # [seconds]
            'minimum': 5, # [seconds]
            'stride' : 0, # [seconds]
            'name': 5  } 
    directory= '/static/images/spectrograms'
    step=1
    if step>0:
        for birdnr,path in enumerate(file):
            if not os.path.exists(directory):
                os.makedirs(directory)
            if not os.path.exists(directory+path.rsplit('/',1)[1].replace(' ', '')[:-4]+"1_1.png"):
                y, sr = librosa.load(path,mono=True)
                y = no.reduce_noise(y, sr)  
                step = (size['desired']-size['stride'])*sr 
                nr=0
                for start, end in zip(range(0,len(y),step),range(size['desired']*sr,len(y),step)):
                    nr=nr+1
                    if end-start > size['minimum']*sr:
                        melpath=path.rsplit('/',1)[1]
                        melpath=path+melpath.replace(' ', '')[:-4]+str(nr)+"_"+str(nr)+".png"
                        saveMel2(y[start:end],melpath)                
    else:    
        print("Error: Stride should be lower than desired length.")
8
Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article