PyAudio - Convert stream.read into int to get amplitude
<p>I'm trying to record audio and simultaneously print the amplitude of the recorded signal. So I'm saving all datas in stream.read. But when I try to print them, I have a string of bytes and no integers. I would like to know how to convert these signs in order to get amplitude.</p>

<p>This is my code :</p>

<pre><code>import pyaudio
import wave

CHUNK = 1024 
FORMAT = pyaudio.paInt16
CHANNELS = 1 
RATE = 44100 
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"

p = pyaudio.PyAudio()

stream = p.open(format=FORMAT,
                channels=CHANNELS,
                rate=RATE,
                input=True,
                frames_per_buffer=CHUNK) 

print("* recording")

frames = []

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
    data = stream.read(CHUNK)
    frames.append(data) # 2 bytes(16 bits) per channel

print("* done recording")

stream.stop_stream()
stream.close()
p.terminate()

for data in frames:
    print(data)
</code></pre>

<p>And this is what I obtain :</p>

<blockquote>
<pre><code>       ����#  ����
          
 !$
          

                 ��  ���� ��������������������������
           ������  �� ��                                           
��

   �� ������ ����������������������������
                            ��    
                                     ����                                                
</code></pre>
  
  <p>������������������������������������������������������������������</p>
  
  <p>���������
           ���������������
                                  
                                               </p>
  
  <p>%  �� ��(��)����,����.����%����#��
                                   ��   �� �����������������������</p>
</blockquote>