0

I am trying to record device audio using Python. It seems that pyaudio only works with external devices. It seems that sounddevice as sd is the answer as it lets us choose default device. The code is

sd.query_devices()

to get the list of available devices and

sd.default.device

to chose from them.

I am trying the codes from https://python-sounddevice.readthedocs.io. All of them works with external devices in spyder. When I write

sd.default.device = 5

it gives errors. When I try sd.default.device = 5 which is Speakers (Realtek HD Audio output), Windows WDM-KS (0 in, 2 out) it gives the error that it is not an input device. I understand the error, But I dont know even when I give an input device like 0 Microsoft Sound Mapper - Input, MME (2 in, 0 out) it is not working to record the device audio.

  • when working with audio, the OS is often important. libraries try their best to make it OS independent, but knowing what OS your're working with may help. It's also important to share the exact error messages you're getting so we can help you determine the problem especially if we can't directly reproduce them ourselves. In particular I have never had a problem with pyaudio, but I do understand that hardware compatibility can be tricky. – Aaron Jul 01 '20 at 18:46
  • Hi, I am using Windows 10. Yeah, I understand I should have stated the error. Actually at the time of writing this query I was not sure about teh error. Now I undersatnd. When I try sd.default.device = 5 which is Speakers (Realtek HD Audio output), Windows WDM-KS (0 in, 2 out) it gives the error that it is not an input device. I understand the error, But I dont know even when I give an inpit device like 0 Microsoft Sound Mapper - Input, MME (2 in, 0 out) it is not working to record the device audio. – Khabbab Zakaria Jul 01 '20 at 18:55
  • When you set `sd.default.device = 0` then call `sd.query_devices()` does it show a star next to MS sound mapper? what is the error you get / what is not working? I was able to set the device to an appropriate input, make a recording, set the device to an output, and play the recording without errors. – Aaron Jul 01 '20 at 19:23
  • @Aaron, sd.default.device = 0 is working but only when I speak with a mic.It is not or almost not working to record lets say an Youtube video's audio taht I am running in the computer. How did you do it? Can you explain? – Khabbab Zakaria Jul 01 '20 at 19:27
  • Yes, when I run the code as you said then it does show the star beside MS sound mapper – Khabbab Zakaria Jul 01 '20 at 19:34
  • Ok, now I understand. I wasn't clear that you were trying to record system sounds rather than a microphone. I thought you meant internal device like built-in mic vs usb mic or line in. [Here's](https://stackoverflow.com/questions/26573556/record-speakers-output-with-pyaudio) what you need. Specifically, you need to go into windows sound settings, and create a stereo mixer as a software input device. – Aaron Jul 01 '20 at 19:54
  • Also `pyaudio` and `sounddevice` are just wrappers on the same library (PortAudio). There should be no real difference in capability between them. Only differences in semantics. – Aaron Jul 01 '20 at 19:56

0 Answers0