获取设备列表
(self, update: bool = True)
| 818 | printt("Infer time: %.2f", total_time) |
| 819 | |
| 820 | def get_devices(self, update: bool = True): |
| 821 | """获取设备列表""" |
| 822 | if update: |
| 823 | sd._terminate() |
| 824 | sd._initialize() |
| 825 | devices = sd.query_devices() |
| 826 | hostapis = sd.query_hostapis() |
| 827 | for hostapi in hostapis: |
| 828 | for device_idx in hostapi["devices"]: |
| 829 | devices[device_idx]["hostapi_name"] = hostapi["name"] |
| 830 | input_devices = [ |
| 831 | f"{d['name']} ({d['hostapi_name']})" |
| 832 | for d in devices |
| 833 | if d["max_input_channels"] > 0 |
| 834 | ] |
| 835 | output_devices = [ |
| 836 | f"{d['name']} ({d['hostapi_name']})" |
| 837 | for d in devices |
| 838 | if d["max_output_channels"] > 0 |
| 839 | ] |
| 840 | input_devices_indices = [ |
| 841 | d["index"] if "index" in d else d["name"] |
| 842 | for d in devices |
| 843 | if d["max_input_channels"] > 0 |
| 844 | ] |
| 845 | output_devices_indices = [ |
| 846 | d["index"] if "index" in d else d["name"] |
| 847 | for d in devices |
| 848 | if d["max_output_channels"] > 0 |
| 849 | ] |
| 850 | return ( |
| 851 | input_devices, |
| 852 | output_devices, |
| 853 | input_devices_indices, |
| 854 | output_devices_indices, |
| 855 | ) |
| 856 | |
| 857 | def set_devices(self, input_device, output_device): |
| 858 | """设置输出设备""" |
no outgoing calls
no test coverage detected