code: def device_info(index=None):
      
      if index is None:
          return (device_info(i) for i in range(_pa.Pa_GetDeviceCount()))
      else:
          info = _pa.Pa_GetDeviceInfo(index)
          if not info:
              raise RuntimeError("Invalid device")
          assert info.structVersion == 2
  
          if 'DirectSound' in hostapi_info(info.hostApi)['name']:
              enc = 'mbcs'
          else:
              enc = 'utf-8'
  
          return {'name': ffi.string(info.name).decode(encoding=enc,
                                                       errors='ignore'),
                  'hostapi': info.hostApi,
                  'max_input_channels': info.maxInputChannels,
                  'max_output_channels': info.maxOutputChannels,
                  'default_low_input_latency': info.defaultLowInputLatency,
                  'default_low_output_latency': info.defaultLowOutputLatency,
                  'default_high_input_latency': info.defaultHighInputLatency,
                  'default_high_output_latency': info.defaultHighOutputLatency,
                  'default_samplerate': info.defaultSampleRate}
docs: Return a generator with information about each device.
  
      If index is given, only one dictionary for the given device is
      returned.