I am trying to plot the waveform of an audio file in Python.
This is my code (I am using the Librosa library):
import plot as plt
def save_plot(filename):
y, sr = librosa.load(filename)
plt.plot(y, 'audio', 'time', 'amplitude')
Where the plot.py file is:
import matplotlib.pylab as plt
def plot(vector, name, xlabel=None, ylabel=None):
plt.figure()
plt.plot(vector)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.plot()
plt.savefig('static/plots/' + name)
The weird thing is that, even though I get a plot that seems like a valid waveform:
The audio file is only 5 seconds long. Therefore, I don't understand what the x axis is talking about; it seems to go up to 90000?
Thanks