4

Is there any way to detect system sound instead of microphone sound? I want to be able to detect whenever my system makes a sound instead of when the microphone picks up the actual sound.

One way I found to do this use an "audio loop-back in either software or hardware (e.g. connect a lead from the speaker 'out' jack to the microphone 'in' jack)."

Capturing speaker output in Java

I am building a program that plays an mp3 file whenever a system sound happens but I don't want it to go off if the dog barks.

Thanks!

Community
  • 1
  • 1
Mushmellow
  • 43
  • 1
  • 3

1 Answers1

2

What about something with pyaudio (http://people.csail.mit.edu/hubert/pyaudio/)

Like this:

import pyaudio

chunk = 1024

p = pyaudio.PyAudio()

stream = p.open(format=pyaudio.paInt16,
                channels=1,
                rate=44100,
                input=True,
                frames_per_buffer=chunk)

data = stream.read(chunk)

And then you could calculate the root-mean-square(RMS) of the audio sample and go from there.

Edited: You can see what kind of devices you can use by doing something like the following. (http://people.csail.mit.edu/hubert/pyaudio/docs/#pyaudio.PyAudio.get_device_info_by_index)

import pyaudio    
p = pyaudio.PyAudio()

for i in xrange(0,10):
    try:
        p.get_device_info_by_index(i)
    except Exception,e:print e
jmunsch
  • 22,771
  • 11
  • 93
  • 114