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

pyaudio: Invalid Device #47

Closed
theritvars opened this issue Oct 9, 2018 · 9 comments
Closed

pyaudio: Invalid Device #47

theritvars opened this issue Oct 9, 2018 · 9 comments

Comments

@theritvars
Copy link

theritvars commented Oct 9, 2018

This is the error I get when trying to launch the script.

(disco-led) C:\Systematic-LEDs\python>python main.py
Could not find settings.ini
No user colours found
No user gradients found
Traceback (most recent call last):
  File "main.py", line 2014, in <module>
    microphone = Microphone(microphone_update)
  File "main.py", line 830, in __init__
    device_info = py_audio.get_device_info_by_host_api_device_index(0,i)
  File "C:\Users\Ritvars\Anaconda3\envs\disco-led\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

PyAudio get_default_input_device_info() output:

>>> import pyaudio
>>> pa = pyaudio.PyAudio()
>>> pa.get_default_input_device_info()
{'index': 1, 'structVersion': 2, 'name': 'VoiceMeeter Aux Output (VB-Audi', 'hostApi': 0, 'maxInputChannels': 8, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defaultHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}

Any ideas?

@ReMiXs
Copy link

ReMiXs commented Nov 8, 2018

I need help too. I have this same problem

@ReMiXs
Copy link

ReMiXs commented Nov 8, 2018

@RichusX Im solved it! Find microphone.py and change method def get_audio_devices() to
(im bolded important fragment)

def get_audio_devices():
#print( "get audio" )
global p
numdevices = p.get_device_count()
#for each audio device, determine if is an input or an output and add it to the appropriate list and dictionary
audio_options = 'Default'

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

if device_info.get('maxInputChannels')>0:
name = device_info.get('name')
audio_options += ',' + name
#print ( audio_options )
return audio_options

@ReMiXs
Copy link

ReMiXs commented Nov 8, 2018

I have next problem. Im solved it. Just use all my code from microphone.py

`import time
import numpy as np
import pyaudio
import lib.config as config
from lib.config import log

ext_gui = None
stream = None
p = pyaudio.PyAudio()

def get_audio_devices():
#print( "get audio" )
global p
numdevices = p.get_device_count()
#for each audio device, determine if is an input or an output and add it to the appropriate list and dictionary
audio_options = 'Default'

for i in range (p.get_device_count()):
device_info = p.get_device_info_by_index(i)
if device_info.get('maxInputChannels')>0:
name = device_info.get('name')
audio_options += ',' + name
#print ( audio_options )
return audio_options

def microphone_register_gui( gui ):
global ext_gui
ext_gui = gui

def reset_microphone_device():
global stream
if stream is not None:
stream.stop_stream()
stream.close()
stream = None

def start_stream(callback):
global stream, p, ext_gui

id = -1

while id == -1:
try:
id=p.get_default_input_device_info()['index']
except IOError:
log('Cannot find microphone.')
time.sleep( 5 )

frames_per_buffer = int(config.settings["configuration"]["MIC_RATE"] / config.settings["configuration"]["FPS"])

overflows = 0
prev_ovf_time = time.time()
prev_time = time.time()
adjustment_factor = 0.0
while True:
try:
if stream is None:
numdevices = p.get_device_count()
#for each audio device, determine if is an input or an output and add it to the appropriate list and dictionary
for i in range (p.get_device_count()):
device_info = p.get_device_info_by_index(i)
if device_info.get('maxInputChannels')>0:
log( "Audio Device Found : " + device_info.get('name'), 4 )
if device_info.get('name')==config.settings["configuration"]["MIC_NAME"]:
id=i
log( "Found Requested Microphone : " + device_info.get('name'), 3 )

    stream = p.open(format=pyaudio.paInt16,
            channels=1,
            rate=config.settings["configuration"]["MIC_RATE"],
            input=True,
            input_device_index = id,
            frames_per_buffer=frames_per_buffer)
            
  time2 = time.time()
  if config.uses_audio :
    y = np.fromstring(stream.read(frames_per_buffer), dtype=np.int16)
    y = y.astype(np.float32)
    prev_time = time.time()
  else:
    y = 0
    desired_sleep = 1.0/config.settings["configuration"]["FPS"]
    last_loop = time.time() - prev_time
    if abs(last_loop - desired_sleep) > 0.0005: 
      if last_loop > desired_sleep:
        adjustment_factor -= 0.0005
      else:
        adjustment_factor += 0.0005
    sleep_time = desired_sleep + adjustment_factor
    prev_time = time.time()
    time.sleep( max( 0, sleep_time ) )
  callback(y)
  
  
except IOError:
  overflows += 1
  if time.time() > prev_ovf_time + 1:
    prev_ovf_time = time.time()
    if config.settings["configuration"]["USE_GUI"]:
      ext_gui.label_error.setText('Audio buffer has overflowed {} times'.format(overflows))
    else:
      log('Audio buffer has overflowed {} times'.format(overflows))

stream.stop_stream()
stream.close()
p.terminate()
`

@theritvars
Copy link
Author

@ReMiXs that's great! I'll give it a go.

@ReMiXs
Copy link

ReMiXs commented Nov 16, 2018

@RichusX nice :)

@Murattemel
Copy link

@RichusX Im solved it! Find microphone.py and change method def get_audio_devices() to
(im bolded important fragment)

def get_audio_devices():
#print( "get audio" )
global p
numdevices = p.get_device_count()
#for each audio device, determine if is an input or an output and add it to the appropriate list and dictionary
audio_options = 'Default'

for i in range (p.get_device_count()): device_info = p.get_device_info_by_index(i)
if device_info.get('maxInputChannels')>0:
name = device_info.get('name')
audio_options += ',' + name
#print ( audio_options )
return audio_options

where did you find "microphone.py" ? there is no such a thing into "Systematic-LEDs" file.

@Murattemel
Copy link

Murattemel commented Dec 5, 2018

Could you please share if you get it somewhere else ?

@TheBroTMv2
Copy link

i got first that error when i was using anaconda with python 2.7 please double check if that is the case then i tried python 3.6 and voila no problems

@plabonhasan
Copy link

plabonhasan commented Jan 12, 2019

problem

(RGB) C:\systematic\python>python main.py

No user colours found No user gradients found

dear i am not professional, how can i easy way to solved it

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

No branches or pull requests

5 participants