1

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.

2 Answers 2

2

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

Start here

http://www.techmind.org/audio/specanaly.html

I am sure there are others.

1
  • You point out a linkt to a graphical Windows application. This is not helpful in the context of a Raspberry Pi.
    – kwasmich
    Oct 25, 2018 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.