title: Get an audio sample as float number from pyaudio-stream
body: <p>As I am currently about to build a device based on a Raspberry Pi for measuring some stuff from noise recorded with a sound card (e.g. variance), and trying to do this within python, I got stuck figuring out how to get a an audiosample as float-number for further calculations.  </p>
  
  <p>What did I do:<br>
  Took a Line-In-to-chinch-adapter and touching the plugs for generating some sort of test signal.<br>
  Recording to for example Audacity or Matlab shows plausible results, like</p>
  
  <p><img src="https://i.stack.imgur.com/AN9kV.png" alt="enter image description here"></p>
  
  <p>What I want to get:<br>
  In ideal, I want to get for example 5 frames á 1024 samples from the sound card, and convert them into a list, tuple or numpy array as a float number for further calculations.</p>
  
  <p>When trying to achieve this with python/pyaudio with the code at the end of this post, I got something like this: </p>
  
  <p><img src="https://i.stack.imgur.com/NGUVw.png" alt="enter image description here"></p>
  
  <p>Due to the fact that the values I got with python seem to differ from them in Matlab (and others) by the factor of about two, I think I've overseen something or did something wrong.
  I think I made a mistake somewhere at the struct.unpack region, but can't figure out where exactly or why.
  I'd like to ask you for help, pointing out where the error is and what I did wrong.</p>
  
  <p>Little testcode for getting some samples and plotting them:</p>
  
  <pre><code>import pyaudio
  import struct
  import matplotlib.pyplot as plt
  
  FORMAT = pyaudio.paFloat32
  SAMPLEFREQ = 44100
  FRAMESIZE = 1024
  NOFFRAMES = 220
  p = pyaudio.PyAudio()
  print('running')
  
  stream = p.open(format=FORMAT,channels=1,rate=SAMPLEFREQ,input=True,frames_per_buffer=FRAMESIZE)
  data = stream.read(NOFFRAMES*FRAMESIZE)
  decoded = struct.unpack(str(NOFFRAMES*FRAMESIZE)+'f',data)
  
  stream.stop_stream()
  stream.close()
  p.terminate()
  print('done')
  plt.plot(decoded)
  plt.show()
  </code></pre>