2

Using python - I want to be able to sample in 2 second chunks, the audio that is being played through the output audio device on the computer.

My goal is to be able to detect a specific noise that comes through the speakers of a PC using Python, and this is the first step in doing so.

I have taken a look at the sounddevice docs but can't seem to determine the correct way to achieve this behaviour, the documentation doesn't appear to cover this.

Please can somebody help out?

It appears I am looking for some form of audio lookback recording in python.

RenegadeAndy
  • 5,440
  • 18
  • 70
  • 130
  • @szatmary this is my repost as per your request. – RenegadeAndy Nov 09 '19 at 14:27
  • 1
    The `sounddevice` module can only record what the underlying [PortAudio](http://portaudio.com/) library provides as "input devices". To record the *output* of some other application(s), you would need to turn it into a usable input device, which cannot be done with the `sounddevice` module and PortAudio. Depending on your operating system there may be ways to do this, but I guess they have nothing to with "python" or "python-sounddevice" (so you should use different tags for your question). You should probably search for "audio loopback device"? – Matthias Nov 10 '19 at 09:13
  • Adjusted question - thank you! But what tag do you suggest - loopback isn't right, and there is no audio loopback? – RenegadeAndy Nov 10 '19 at 18:22
  • This is highly platform-dependent, so you should mention your operating system, there should be tags for most operating systems. You can also mention a certain audio sub-system if you want to be more specific. The "loopback" tag seems to be extremely generic, but I guess it is technically appropriate to your question. Mentioning "Python" in your tags will not help at all. You could also simply use a search engine and type in " audio loopback", and you should find all the information you need (probably more than you need ...). – Matthias Nov 11 '19 at 11:35
  • Nevertheless, I want to do this all programmatically, and if i have to configure this outside of my program, then thats a setup step for the users i want to avoid. Therefore I want to try to do this in a completely automated manner, for mac osx and windows. – RenegadeAndy Nov 11 '19 at 14:11
  • 1
    It’s not really possible on Mac. On Mac people use a tools called “sound flower” to accomplish this. Take a look at the OBS code for examples. – szatmary Nov 11 '19 at 16:59
  • This statement is not verifiable, but I'm still quite confident it's true: This is currently not possible. You'll have to use separate solutions for each OS. – Matthias Nov 11 '19 at 17:40
  • szatmary can you draw my attention to a particular area of the OBS source code? Perhaps where they use sound flower? – RenegadeAndy Nov 11 '19 at 19:26
  • How about debugging the program executable (game, I assume) and figuring out where exactly in the assembly code is the sound generated? Then you can either modify the executable, or use some other mechanism to execute your desired action when the sound is generated (though I'm not sure if such mechanism exists). – kyrill Nov 14 '19 at 14:16

0 Answers0