Get sample audio as floating point from pyaudio-stream

Since I'm currently going to create a Raspberry Pi-based device to measure some interference from noise recorded on a sound card (like dispersion), and trying to do this in python, I'm stuck figuring out how to get an audio camera as a floating-point number for further calculations.

What I did:
I took the Line-In-to-chinch adapter and touched the connectors to create a kind of test signal.
A record like Audacity or Matlab shows plausible results like

enter image description here

:
, , 5 1024 , numpy .

python/pyaudio , - :

enter image description here

, , python, -, Matlab ( ) , , - - . , - struct.unpack, , . , , .

:

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()
+3
1

numpy.fromstring "struct.unpack":

import numpy
stream = p.open(format=FORMAT,channels=1,rate=SAMPLEFREQ,input=True,frames_per_buffer=FRAMESIZE)
data = stream.read(NOFFRAMES*FRAMESIZE)
decoded = numpy.fromstring(data, 'Float32');

,

+9

All Articles