title: Getting spectrogram from recorded audio , ERROR: "ParameterError: Audio buffer is not finite everywhere"
body: <p>I'm trying to record a sound using 'pyaudio' and get a spectrogram for the audio, but I get the above error: " Audio buffer is not finite everywhere".
  It might be a possible duplicate, but I didn't find something which solves the eroror. Here is my code:</p>
  
  <pre><code>CHUNK = 96000 # number of data points to read at a time
  RATE = 16000 # time resolution of the recording device (Hz)
  p=pyaudio.PyAudio() # start the PyAudio class
  stream=p.open(format=pyaudio.paInt16,channels=1,rate=RATE,input=True,
                frames_per_buffer=CHUNK) #uses default input device
  
  # create a numpy array holding a single read of audio data
  stop=0
  while not stop: #to it a few times just to see
      print('Recording')
      audio=np.frombuffer(stream.read(CHUNK))
      print(type(audio[0]))
      print("max value: ",np.max(audio))
      print("min value: ",np.min(audio))
      sd.play(audio,RATE)
      S = librosa.feature.melspectrogram(audio, sr=RATE)
      S = 10 * np.log(S + 1e-15)
      #em=get_emotion_audio(audio,RATE)
      #print("[DETECTED] ",em)
      stop=1 
  # close the stream gracefully
  stream.stop_stream()
  stream.close()
  p.terminate()
  </code></pre>
  
  <p>Here is the error I'am getting:</p>
  
  <pre><code>'''
  Recording
  &lt;class 'numpy.float64'&gt;
  max value:  nan
  min value:  nan
  ---------------------------------------------------------------------------
  ParameterError                            Traceback (most recent call last)
  &lt;ipython-input-3-33fa263f625d&gt; in &lt;module&gt;
       19     print("min value: ",np.min(audio))
       20     sd.play(audio,RATE)
  ---&gt; 21     S = librosa.feature.melspectrogram(audio, sr=RATE)
       22     S = 10 * np.log(S + 1e-15)
       23     #em=get_emotion_audio(audio,RATE)
  
  ~\Anaconda3\lib\site-packages\librosa\feature\spectral.py in melspectrogram(y, sr, S, n_fft, hop_length, power, **kwargs)
     1529 
     1530     S, n_fft = _spectrogram(y=y, S=S, n_fft=n_fft, hop_length=hop_length,
  -&gt; 1531                             power=power)
     1532 
     1533     # Build a Mel filter
  
  ~\Anaconda3\lib\site-packages\librosa\core\spectrum.py in _spectrogram(y,     S, n_fft, hop_length, power)
     1555     else:
     1556         # Otherwise, compute a magnitude spectrogram from input
  -&gt; 1557         S = np.abs(stft(y, n_fft=n_fft, hop_length=hop_length))**power
     1558 
     1559     return S, n_fft
  
  ~\Anaconda3\lib\site-packages\librosa\core\spectrum.py in stft(y, n_fft, hop_length, win_length, window, center, dtype, pad_mode)
      159 
      160     # Check audio is valid    
  --&gt; 161     util.valid_audio(y)
      162 
      163     # Pad the time series so that frames are centered
  
  ~\Anaconda3\lib\site-packages\librosa\util\utils.py in valid_audio(y, mono)
      168 
      169     if not np.isfinite(y).all():
  --&gt; 170         raise ParameterError('Audio buffer is not finite everywhere')
      171 
      172     return True
  
  ParameterError: Audio buffer is not finite everywhere
      '''
  </code></pre>