Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I listen event of Switching current default audio device? #80

Open
tihoangyeudau opened this issue Sep 15, 2023 · 1 comment
Open

Comments

@tihoangyeudau
Copy link

I want to listen event of Switching default audio device in win32, how can i do? thank you so much?

@TJ-59
Copy link

TJ-59 commented Sep 23, 2024

MMNotificationClient from pycaw.callbacks (which you should inherit in your own class unless you only want the basic prints for dev purpose, if it even have any), it has on_default_device_changed(), on_device_added(), on_device_removed(), on_device_state_changed(), and on_property_value_changed().

You probably want on_default_device_changed().
It would trigger for both eRender and eCapture, and on different roles as well, meaning it could show a change in default speakers as well as a change in default microphone, both for multimedia use or for communication use.

def on_default_device_changed(flow, flow_id, role, role_id, default_device_id):
    Is fired, when the default endpoint device for a role changed.
    flow : str
        String explaining the data-flow direction.
    flow_id: int
        Id of the data-flow direction.
    role : str
        String explaining the role of the device.
    role_id: int
        Id of the role.
    default-device_id: str
        String containing the default device id.
Roles = ["eConsole", "eMultimedia", "eCommunications", "ERole_enum_count"]
DataFlow = ["eRender", "eCapture", "eAll", "EDataFlow_enum_count"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants