Fix AttributeError: module ‘librosa’ has no attribute ‘output’ – Librosa Tutorial

By | November 16, 2021

If you plan to use python librosa to save a audio file, you may use code below:

librosa.output.write_wav('file_trim_5s.wav', y, sr)

librosa.output.write_wav() function allows us to save a numpy array to wav file. However, you may get this error: AttributeError: module ‘librosa’ has no attribute ‘output’. In this tutorial, we will introduce how to fix it.

How to fix this AttributeError?

Because librosa.output.write_wav() has been removed from librosa. In order to save a wav file, you can use soundfile.write().

Here is an example:

import numpy as np
import soundfile as sf
sf.write('stereo_file.wav', np.random.randn(10, 2), 44100, 'PCM_24')

How about soundfile.write()?

soundfile.write() is defined as the following:

soundfile.blocks(file, blocksize=None, overlap=0, frames=-1, start=0, stop=None, dtype='float64', always_2d=False, fill_value=None, out=None, samplerate=None, channels=None, format=None, subtype=None, endian=None, closefd=True)

You can find more detail on it in here: