1

win10 anaconda environment, remote desk access to this workstation

conda, anaconda and anaconda-navigate all updated

I used conda to install the pyaudio (have tried pip install the 'whl' file, same result)

I would like to record the system audio e.g. mp3 audio or stream audio data, not the microphone input. But I still have tried both enabled/disable 'setting' --> 'privacy' --> 'microphone', none of them works.

Here is my code:

import pyaudio
p = pyaudio.PyAudio()
stream_in = p.open(
    rate = 44100,
    channels = 2,
    format = pyaudio.paInt16,
    input = True,                   # input stream flag
    input_device_index = 3,         # select the Stereo Mix
    frames_per_buffer = 1024
)

It returns the error message: OSError: [Errno -9999] Unanticipated host error

I checked the audio device in the system:

for i in range(p.get_device_count()):
    devInfo = p.get_device_info_by_index(i)
    print(devInfo)

And it gives 6 result:

{'index': 0, 'structVersion': 2, 'name': 'Microsoft Sound Mapper - Output', 'hostApi': 0, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'defaultLowInputLatency': 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defaultHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}
{'index': 1, 'structVersion': 2, 'name': 'Remote Audio', 'hostApi': 0, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'defaultLowInputLatency': 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defaultHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}
{'index': 2, 'structVersion': 2, 'name': 'Line In (Realtek HD Audio Line input)', 'hostApi': 1, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.04, 'defaultHighOutputLatency': 0.04, 'defaultSampleRate': 44100.0}
{'index': 3, 'structVersion': 2, 'name': 'Stereo Mix (Realtek HD Audio Stereo input)', 'hostApi': 1, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.04, 'defaultHighOutputLatency': 0.04, 'defaultSampleRate': 44100.0}
{'index': 4, 'structVersion': 2, 'name': 'Speakers (Realtek HD Audio rear output)', 'hostApi': 1, 'maxInputChannels': 0, 'maxOutputChannels': 6, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.04, 'defaultHighOutputLatency': 0.04, 'defaultSampleRate': 44100.0}
{'index': 5, 'structVersion': 2, 'name': 'Microphone (Realtek HD Audio Mic input)', 'hostApi': 1, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.04, 'defaultHighOutputLatency': 0.04, 'defaultSampleRate': 44100.0}

Since I want the system audio, not recording the sound from the microphone, I selected index 3 which is the 'Stereo Mix'.

The sound icon in the taskbar shows two 'Remote Audio', no other choise. I also checked the default device:

defaultCapability = p.get_default_host_api_info()
print(defaultCapability)

output:
{'index': 0, 'structVersion': 1, 'type': 2, 'name': 'MME', 'deviceCount': 2, 'defaultInputDevice': -1, 'defaultOutputDevice': 1}

Then I omit the 'input_device_index' to use the default one, and got OSError: [Errno -9996] Invalid input device (no default output device)

Anyone can help me figure out which device I should select? Thanks a lot.

Aaron
  • 33
  • 4
  • Look at this post: https://stackoverflow.com/questions/26573556/record-speakers-output-with-pyaudio – JoraSN Jan 03 '22 at 00:01

0 Answers0