Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

librosa.display.waveplot(np.array(f),sr=22050)-----AttributeError: 'module' object has no attribute 'display'

Tags:

python

librosa

Referring to this link: https://aqibsaeed.github.io/2016-09-03-urban-sound-classification-part-1/, I am trying to make the same waveplot figure, however,i run the code through .py, there is the error:

(tensorflow) yyydeMacBook-Pro:~ yyy$ python /Users/yyy/Desktop/1.py 
Traceback (most recent call last):
  File "/Users/yyy/Desktop/1.py", line 82, in <module>
    plot_waves(sound_names,raw_sounds)
  File "/Users/yyy/Desktop/1.py", line 42, in plot_waves
    librosa.display.waveplot(np.array(f),sr=22050)
AttributeError: 'module' object has no attribute 'display'
like image 651
Yiin Avatar asked Apr 21 '17 02:04

Yiin


3 Answers

From this github issue I read that it is now necessary to import librosa.display.

[Update 2022] Apparently now also waveplot needs to be changed to waveshow, like below: (thanks to Hammad Hassan in comments!)

import librosa.display
plt.figure(figsize=(12, 4))
librosa.display.waveshow(data, sr=sampling_rate)
like image 70
Herman Avatar answered Oct 23 '22 09:10

Herman


just import the display

import librosa.display
plt.figure(figsize=(12, 4))
librosa.display.waveplot(data, sr=sampling_rate)

output

like image 41
Rahul Verma Avatar answered Oct 23 '22 09:10

Rahul Verma


If you are running librosa 0.9.0 you will run into following Error using waveplot:

AttributeError: module 'librosa.display' has no attribute 'waveplot'

instead: import librosa.display and use waveshow

path = "sample.wav"
data, sampling_rate = librosa.load(path)
librosa.display.waveshow(data, sr=sampling_rate)
like image 9
Joe Web Avatar answered Oct 23 '22 07:10

Joe Web