2020-11-03 21:24:45 +00:00
|
|
|
import sounddevice as sd
|
|
|
|
import importlib
|
2020-11-03 21:28:05 +00:00
|
|
|
from helpers.os_environment import isMacOS
|
|
|
|
|
2020-11-03 21:24:45 +00:00
|
|
|
|
|
|
|
class DeviceManager():
|
|
|
|
|
2020-11-03 21:28:05 +00:00
|
|
|
@classmethod
|
|
|
|
def _isOutput(self, device):
|
|
|
|
return device["max_output_channels"] > 0
|
2020-11-03 21:24:45 +00:00
|
|
|
|
2020-11-03 21:28:05 +00:00
|
|
|
@classmethod
|
|
|
|
def _getDevices(self):
|
|
|
|
# To update the list of devices
|
|
|
|
# Sadly this doesn't work on MacOS.
|
|
|
|
if not isMacOS():
|
|
|
|
sd._terminate()
|
|
|
|
sd._initialize()
|
|
|
|
devices = sd.query_devices()
|
|
|
|
return devices
|
2020-11-03 21:24:45 +00:00
|
|
|
|
2020-11-03 21:28:05 +00:00
|
|
|
@classmethod
|
|
|
|
def getOutputs(self):
|
|
|
|
outputs = filter(self._isOutput, self._getDevices())
|
2020-11-03 21:24:45 +00:00
|
|
|
|
2020-11-03 21:28:05 +00:00
|
|
|
return outputs
|