Python Forum
PyAudio Buffer Data Calculation - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: PyAudio Buffer Data Calculation (/thread-29177.html)



PyAudio Buffer Data Calculation - MclarenF1 - Aug-21-2020

Hi,

I have a question (Sorry I'm not very professional in python).
I'm using PyAudio to capture microphone sound with python (for its Peak Value).
The code is something like this:

p=pyaudio.PyAudio()
stream=p.open(format=pyaudio.paInt16,
              channels=1,rate=RATE,
              input=True,
              frames_per_buffer=CHUNK)
while True:
    data = np.fromstring(stream.read(1024),dtype=np.int16)
    dataMic = data...
    ...
    print("peak values")
When I run the app, it starts to print peak values line by line very fast (values change when microphone get sound)
Now my question is:
How can I calculate the average of for example every 10 peak values (in order) and print the average line by line instead of printing peak values for every frame!?
I know that I should save every 10 peak value result in an (maybe) array and then do the calculation but I don't know how to do it in python :-/ !
Please help me...
Thank you so much for your attention Shy .
Kind Regards.