I am wondering if there is an easy way to measure the amplitude/sound level of an audio signal being input to the rasbperry pi via usb sound card. I would like to play music into the sound card input and have a python script print the sound level in real time. I have looked around at other posts involving pyaudio and scipy.io.wavefile.read, but I am still unsure. Any help is appreciated.
You may want to use pyaudio library.
import pyaudio import audioop CHUNK = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 2 RATE = 44100 RECORD_SECONDS = 60 p = pyaudio.PyAudio() stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK) for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): data = stream.read(CHUNK, exception_on_overflow=False) rms = audioop.rms(data, 2) print(rms) stream.stop_stream() stream.close() p.terminate()
I am sure there are others.