0

I am using PyAudio to detect system sounds produced by my computer and save it into a file. Only sounds originating from the computer will be detected so if a dog barks, it will go ignored by the program.

Given this setup, I think that complete silence is record-able since if the computer makes no sound, then no sound will be detected.

stream = p.open(format=FORMAT,
                channels=CHANNELS,
                rate=RATE,
                input=True,
                frames_per_buffer=CHUNK,
                input_device_index=dev_index
                )
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
    data = stream.read(CHUNK)
    frames.append(data)

From my knowledge, every "chunk" of sound is stored in data which is them appended to frames. I was wondering how I could use data to see if certain sounds were playing or if no sound was playing at all? I have tried printing data but sometime the same silence results in different things being printed.

Geneku2
  • 65
  • 8
  • Even complete silence will pick up noise from the microphone electronics, there will always be some kind of data. Maybe a threshold based on the volume in the noise of the data could be the way to go. – William Jun 23 '21 at 21:56
  • Include your import statements in your code in your question. I've never used pyaudio before. But if I wanted to try it out, I can't do that from your code cause I don't know where `p` came from in `p.open`. Then I don't have to go digging through the pyaudio API. – William Jun 23 '21 at 21:58
  • Maybe this stackexchange post could help out: https://dsp.stackexchange.com/questions/17628/python-audio-detecting-silence-in-audio-signal/17629 – William Jun 23 '21 at 21:59
  • Just a brief idea, but you could try and convert it into a .wav and then measure the amplitude. Never done it before but I hope it helps – The Pilot Dude Jun 23 '21 at 22:06
  • @William There is technically no sound because I linked the recording up to my computer audio, so if the computer isn't making any sound then it will not detect anything. My code is just a modified version of this[link](https://stackoverflow.com/questions/26573556/record-speakers-output-with-pyaudio/) – Geneku2 Jun 23 '21 at 22:25
  • One thing I found was that "noise" chunk usually contain an numbers greater and 5, while "silence" chunks do not. I've been converting the chunks to strings and running seeing if numbers greater than 5 exist, then using that information to detect noise. This doesn't always work, for example: starting the programing or running sound often results in some "lag" error, but overall I found this method great for detecting long term silence or long term sound. – Geneku2 Jun 23 '21 at 22:29

0 Answers0