title: How to convert amplitude to dB in python using Librosa?
body: <p>I have a few questions, which are all very related. The main problem here is to convert the amplitude of an audio file to dB scale and I am doing it as below which I am not sure is correct:</p>
  
  <pre><code>y, sr = librosa.load('audio.wav')
  S = np.abs(librosa.stft(y))
  db_max = librosa.amplitude_to_db(S, ref=np.max)
  db_median = librosa.amplitude_to_db(S, ref=np.median)
  db_min = librosa.amplitude_to_db(S, ref=np.min)
  
  db_max_AVG = np.mean(db_max, axis=0)
  db_median_AVG = np.mean(db_median, axis=0)
  db_min_AVG = np.mean(db_min, axis=0)
  </code></pre>
  
  <p>My question is how can I convert 'y' to dB scale. Is not 'y' the amplitude?
  Also, the shape of 'y' and 'db_max_AVG' is not the same. The size of 'db_max_AVG' is 9137 while the size of 'y' is 4678128.
  Another question is that my audio file is 3 minutes and 32 seconds and the shape of y is:</p>
  
  <pre><code>print(y.shape)
  (4678128,)
  </code></pre>
  
  <p>I do not know what this number represents because it obviously does not represent milliseconds or microseconds. Below you can see two plots of 'y' using different methods:</p>
  
  <pre><code>plt.plot(y)
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/pFaQI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pFaQI.png" alt="enter image description here"></a></p>
  
  <pre><code>librosa.display.waveplot(y, sr=22050, x_axis='time')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/YpDgh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YpDgh.png" alt="enter image description here"></a></p>