2020-12-19 14:57:37 +00:00
|
|
|
from typing import Any, Dict
|
2020-11-03 21:24:45 +00:00
|
|
|
import sounddevice as sd
|
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
|
2020-12-19 14:57:37 +00:00
|
|
|
def _isOutput(cls, device:Dict[str,Any]) -> bool:
|
2020-11-03 21:28:05 +00:00
|
|
|
return device["max_output_channels"] > 0
|
2020-11-03 21:24:45 +00:00
|
|
|
|
2020-11-03 21:28:05 +00:00
|
|
|
@classmethod
|
2020-12-19 14:57:37 +00:00
|
|
|
def _getDevices(cls) -> sd.DeviceList:
|
2020-11-03 21:28:05 +00:00
|
|
|
# To update the list of devices
|
|
|
|
# Sadly this doesn't work on MacOS.
|
|
|
|
if not isMacOS():
|
|
|
|
sd._terminate()
|
|
|
|
sd._initialize()
|
2020-12-19 14:57:37 +00:00
|
|
|
devices: sd.DeviceList = sd.query_devices()
|
2020-11-03 21:28:05 +00:00
|
|
|
return devices
|
2020-11-03 21:24:45 +00:00
|
|
|
|
2020-11-03 21:28:05 +00:00
|
|
|
@classmethod
|
2020-12-19 14:57:37 +00:00
|
|
|
def getOutputs(cls) -> sd.DeviceList:
|
|
|
|
outputs: sd.DeviceList = filter(cls._isOutput, cls._getDevices())
|
2020-11-03 21:24:45 +00:00
|
|
|
|
2020-11-03 21:28:05 +00:00
|
|
|
return outputs
|