def getDevices(): """Get a `list` of audio capture device (i.e. microphones) descriptors. On Windows, only WASAPI devices are used. Returns ------- list List of `AudioDevice` descriptors for suitable capture devices. If empty, no capture devices have been found. """ try: Microphone.enforceWASAPI = bool(prefs.hardware["audioForceWASAPI"]) except KeyError: pass # use default if option not present in settings # query PTB for devices if Microphone.enforceWASAPI and sys.platform == 'win32': allDevs = audio.get_devices(device_type=13) else: allDevs = audio.get_devices() # make sure we have an array of descriptors allDevs = [allDevs] if isinstance(allDevs, dict) else allDevs # create list of descriptors only for capture devices inputDevices = [ desc for desc in [AudioDeviceInfo.createFromPTBDesc(dev) for dev in allDevs] if desc.isCapture ] return inputDevices
def getDevices(kind=None): """Returns a dict of dict of audio devices of specified `kind` kind can be None, 'input' or 'output' The dict keys are names, and items are dicts of properties """ if sys.platform == 'win32': deviceTypes = 13 # only WASAPI drivers need apply! else: deviceTypes = None devs = {} if travisCI: # travis-CI testing does not have a sound device return devs else: allDevs = audio.get_devices(device_type=deviceTypes) # annoyingly query_devices is a DeviceList or a dict depending on number if type(allDevs) == dict: allDevs = [allDevs] for ii, dev in enumerate(allDevs): if kind and kind.startswith('in'): if dev['NrInputChannels'] < 1: continue elif kind and kind.startswith('out'): if dev['NrOutputChannels'] < 1: continue # we have a valid device so get its name # newline characters must be removed devName = dev['DeviceName'].replace('\r\n', '') devs[devName] = dev dev['id'] = ii return devs
def getDevices(kind=None): """Returns a dict of dict of audio devices of specified `kind` The dict keys are names and items are dicts of properties """ devs = {} if travisCI: # travis-CI testing does not have a sound device return devs else: allDevs = audio.get_devices(kind) # annoyingly query_devices is a DeviceList or a dict depending on number if type(allDevs) == dict: allDevs = [allDevs] for ii, dev in enumerate(allDevs): # newline characters must be removed devName = dev['name'].replace('\r\n', '') devs[devName] = dev dev['id'] = ii return devs