Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Method Usage #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix Method Usage #71

wants to merge 1 commit into from

Conversation

david-bour
Copy link

@david-bour david-bour commented Feb 3, 2019

tl;dr

There might have been a mix up with the following available API calls
get_device_info_by_index(device_index)
get_device_count()
get_host_api_count()
get_host_api_info_by_index(host_api_index)
get_device_info_by_host_api_device_index(host_api_index, host_api_device_index)

The incorrect method was being used for finding the device which led to an IndexError. Since we're attempting to add all of the devices, we should be using the method 'get_device_info_by_index` which will properly fetch the amount of devices we have.

This issue was also raised in #47 and #53

Issue

Run PyAudio().get_default_host_api_info()

Windows 10

{'index': 0, 'structVersion': 1, 'type': 2, 'name': 'MME', 'deviceCount': 5, 'defaultInputDevice': 1, 'defaultOutputDevice': 3}
>>> for i in range(py_audio.get_device_count()):
...     device_info = py_audio.get_device_info_by_host_api_device_index(0, i)
...     print(device_info)
...
{'index': 0, 'structVersion': 2, 'name': 'Microsoft Sound Mapper - Input', 'hostApi': 0, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defaultHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}
{'index': 1, 'structVersion': 2, 'name': 'VoiceMeeter Output (VB-Audio Vo', 'hostApi': 0, 'maxInputChannels': 8, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defaultHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}
{'index': 2, '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': 3, 'structVersion': 2, 'name': 'VoiceMeeter Input (VB-Audio Voi', 'hostApi': 0, 'maxInputChannels': 0, 'maxOutputChannels': 8, 'defaultLowInputLatency': 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defaultHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}
{'index': 4, 'structVersion': 2, 'name': 'Speakers (Realtek High Definiti', 'hostApi': 0, 'maxInputChannels': 0, 'maxOutputChannels': 8, 'defaultLowInputLatency': 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defaultHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "D:\Programs\Anaconda\envs\esp\lib\site-packages\pyaudio.py", line 852, in get_device_info_by_host_api_device_index
    host_api_device_index)
OSError: [Errno -9996] Invalid device

Looking into the docs further, we see that the Invalid device error is described as

A paInvalidDevice error code indicates that the hostApiDeviceIndex parameter is out of range.

source: portaudio docs

If I do PyAudio().get_device_count() , it lists 13 devices! That's way more than I have when I checked it using PyAudio().get_default_host_api_info() and PyAudio().get_host_api_count() which lists 2.

So what this means is if I try PyAudio().get_device_info_by_host_api_device_index(0,index), I will always have an index error because the host only has 2 while I have 13 devices in total on my setup. Sometimes this will work seamlessly for people because their rig has the same amount of devices as their PortAudio Host APIs count.

The fix is to simply swap out the method call to get_device_info_by_index(device_index)

The incorrect method was being used for finding the device which led to
an IndexError. Since we're attempting to add all of the devices, we
should be using the method 'get_device_info_by_index` which will
properly fetch the amount of devices we have
This was referenced Feb 3, 2019
@Andriejus
Copy link

Thank you! But now I get this error..:(

(RGB) bash-3.2$ python main.py
No user colours found
No user gradients found
Traceback (most recent call last):
File "main.py", line 1263, in set_mic
microphone.setDevice(mic_button_group.checkedId())
File "main.py", line 858, in setDevice
self.device_id = self.devices[device_id]["index"]
IndexError: list index out of range
Abort trap: 6
(RGB) bash-3.2$

@richyxi
Copy link

richyxi commented Feb 4, 2019

Try adding this line of code in #53

@Andriejus
Copy link

I will try when Im at home. By the way do I need to edit just main.py file or also .gitignore file? Its shown here: 29d3dc9

@richyxi
Copy link

richyxi commented Feb 6, 2019 via email

@Andriejus
Copy link

It worked for me. Now Im able to choose not only microphone or built-in input. But if I make some changes in sound settings on my computer (like disabling microphone), so it crashes. I think you should set your sound settings right before you launch main.py. I played with sound settings and if microphone was disabled, so I couldnt run main.py (it crashes with syntax error). Im trying to find out how to set audio settings right in order to play music from my computer. Now Im able to use it only with microphone. Tried to use program "soundflower", but Im not sure how to use it:) I need to watch some tutorials.

@richyxi
Copy link

richyxi commented Feb 6, 2019 via email

@Andriejus
Copy link

Andriejus commented Feb 6, 2019

Its working now for me. Here are screenshots of my audio configuration:

screen shot 2019-02-06 at 9 40 10 pm
screen shot 2019-02-06 at 9 39 12 pm
screen shot 2019-02-06 at 9 41 18 pm
screen shot 2019-02-06 at 9 39 33 pm
screen shot 2019-02-06 at 9 40 10 pm

@richyxi
Copy link

richyxi commented Feb 6, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants