vmpoll.py
· 876 B · Python
Raw
#!/usr/bin/env python
import voicemeeterlib # pip install voicemeeter-lib
from subprocess import check_output
from time import sleep
DEBUG = False
DEVICE = "Headphones (Bose QuietComfort 35 Series 2 Stereo)" # TODO update with your device name
CMD = "Get-PnpDevice -presentonly | Where-Object FriendlyName -eq '{}'"
def debug(*msg):
if DEBUG: print(*msg)
while True:
with voicemeeterlib.api('banana') as vm:
bus_device = vm.bus[1].device.name == DEVICE
debug()
debug(bus_device)
if check_output(["powershell", "-Command", CMD.format(DEVICE)]):
if not bus_device: vm.bus[1].device.wdm = DEVICE
debug(True, bus_device)
else:
if bus_device: vm.bus[1].device.wdm = ""
debug(False, bus_device)
bus_device = vm.bus[1].device.name == DEVICE
debug(bus_device)
sleep(1)
| 1 | #!/usr/bin/env python |
| 2 | import voicemeeterlib # pip install voicemeeter-lib |
| 3 | from subprocess import check_output |
| 4 | from time import sleep |
| 5 | DEBUG = False |
| 6 | DEVICE = "Headphones (Bose QuietComfort 35 Series 2 Stereo)" # TODO update with your device name |
| 7 | CMD = "Get-PnpDevice -presentonly | Where-Object FriendlyName -eq '{}'" |
| 8 | def debug(*msg): |
| 9 | if DEBUG: print(*msg) |
| 10 | while True: |
| 11 | with voicemeeterlib.api('banana') as vm: |
| 12 | bus_device = vm.bus[1].device.name == DEVICE |
| 13 | debug() |
| 14 | debug(bus_device) |
| 15 | if check_output(["powershell", "-Command", CMD.format(DEVICE)]): |
| 16 | if not bus_device: vm.bus[1].device.wdm = DEVICE |
| 17 | debug(True, bus_device) |
| 18 | else: |
| 19 | if bus_device: vm.bus[1].device.wdm = "" |
| 20 | debug(False, bus_device) |
| 21 | bus_device = vm.bus[1].device.name == DEVICE |
| 22 | debug(bus_device) |
| 23 | sleep(1) |