ScrapExplorer - utils.py
Home / misc / plxkit Lines: 1 | Size: 1194 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1import sounddevice as sd 2import sys 3import time 4 5GREEN = "\033[92m" 6RESET = "\033[0m" 7 8FLAG = "USB AUDIO CODEC" 9 10def list_devices(): 11 print("Fetching audio devices...",end="") 12 sys.stdout.flush() 13 devices = sd.query_devices() 14 sys.stdout.write('\x1b[1A') 15 sys.stdout.write('\x1b[2K') 16 sys.stdout.write('\r') 17 18 print("Suggested PLX device will show in "+GREEN+"green"+RESET+" color.") 19 for i, dev in enumerate(devices): 20 if FLAG in dev['name']: 21 print(f"{GREEN}{i}: {dev['name']} ({dev['max_input_channels']} in, {dev['max_output_channels']} out){RESET}") 22 else: 23 print(f"{i}: {dev['name']} ({dev['max_input_channels']} in, {dev['max_output_channels']} out)") 24 return devices 25 26def get_device_index(name_substring, is_input=True): 27 """Find device index by name substring.""" 28 devices = sd.query_devices() 29 name_substring = name_substring.lower() 30 for i, dev in enumerate(devices): 31 if name_substring in dev['name'].lower(): 32 if is_input and dev['max_input_channels'] > 0: 33 return i 34 if not is_input and dev['max_output_channels'] > 0: 35 return i 36 return None 37[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.