|
6 | 6 |
|
7 | 7 | """Provides a simple Python interface to playing audio using the Windows Audio Session API (WASAPI), as well as other useful utilities.""" |
8 | 8 |
|
9 | | -from collections.abc import Generator |
10 | 9 | import threading |
11 | 10 | import typing |
12 | 11 | from typing import ( |
|
40 | 39 | import core |
41 | 40 | import globalVars |
42 | 41 | from pycaw.utils import AudioUtilities |
43 | | -from pycaw.constants import EDataFlow, DEVICE_STATE |
| 42 | + |
| 43 | +from utils.mmdevice import _getOutputDevices |
44 | 44 |
|
45 | 45 |
|
46 | 46 | __all__ = ( |
@@ -89,44 +89,6 @@ class AudioPurpose(Enum): |
89 | 89 | SOUNDS = auto() |
90 | 90 |
|
91 | 91 |
|
92 | | -class _AudioOutputDevice(typing.NamedTuple): |
93 | | - id: str |
94 | | - friendlyName: str |
95 | | - |
96 | | - |
97 | | -def _getOutputDevices( |
98 | | - *, |
99 | | - includeDefault: bool = False, |
100 | | - stateMask: DEVICE_STATE = DEVICE_STATE.ACTIVE, |
101 | | -) -> Generator[_AudioOutputDevice]: |
102 | | - """Generator, yielding device ID and device Name. |
103 | | - .. note:: Depending on number of devices being fetched, this may take some time (~3ms) |
104 | | -
|
105 | | - :param includeDefault: Whether to include a value representing the system default output device in the generator, defaults to False. |
106 | | - .. note:: The ID of this device is **not** a valid mmdevice endpoint ID string, and is for internal use only. |
107 | | - The friendly name is **not** generated by the operating system, and it is highly unlikely that it will match any real output device. |
108 | | - :param state: What device states to include in the resultant generator, defaults to DEVICE_STATE.ACTIVE. |
109 | | - :return: Generator of :class:`_AudioOutputDevices` containing all enabled and present audio output devices on the system. |
110 | | - """ |
111 | | - if includeDefault: |
112 | | - yield _AudioOutputDevice( |
113 | | - id=typing.cast(str, config.conf.getConfigValidation(("audio", "outputDevice")).default), |
114 | | - # Translators: Value to show when choosing to use the default audio output device. |
115 | | - friendlyName=_("Default output device"), |
116 | | - ) |
117 | | - endpointCollection = AudioUtilities.GetDeviceEnumerator().EnumAudioEndpoints( |
118 | | - EDataFlow.eRender.value, |
119 | | - stateMask.value, |
120 | | - ) |
121 | | - for i in range(endpointCollection.GetCount()): |
122 | | - device = AudioUtilities.CreateDevice(endpointCollection.Item(i)) |
123 | | - # This should never be None, but just to be sure |
124 | | - if device is not None: |
125 | | - yield _AudioOutputDevice(device.id, device.FriendlyName) |
126 | | - else: |
127 | | - continue |
128 | | - |
129 | | - |
130 | 92 | def getOutputDeviceNames() -> list[str]: |
131 | 93 | """Obtain the names of all audio output devices on the system. |
132 | 94 | :return: The names of all output devices on the system. |
|
0 commit comments