-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtwitch_volume.py
142 lines (130 loc) · 5.09 KB
/
twitch_volume.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import win32com
from comtypes import *
import comtypes.client
from ctypes import POINTER
from ctypes.wintypes import DWORD, BOOL
MMDeviceApiLib = \
GUID('{2FDAAFA3-7523-4F66-9957-9D5E7FE698F6}')
IID_IMMDevice = \
GUID('{D666063F-1587-4E43-81F1-B948E807363F}')
IID_IMMDeviceEnumerator = \
GUID('{A95664D2-9614-4F35-A746-DE8DB63617E6}')
CLSID_MMDeviceEnumerator = \
GUID('{BCDE0395-E52F-467C-8E3D-C4579291692E}')
IID_IMMDeviceCollection = \
GUID('{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}')
IID_IAudioEndpointVolume = \
GUID('{5CDF2C82-841E-4546-9722-0CF74078229A}')
class IMMDeviceCollection(IUnknown):
_iid_ = GUID('{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}')
pass
class IAudioEndpointVolume(IUnknown):
_iid_ = GUID('{5CDF2C82-841E-4546-9722-0CF74078229A}')
_methods_ = [
STDMETHOD(HRESULT, 'RegisterControlChangeNotify', []),
STDMETHOD(HRESULT, 'UnregisterControlChangeNotify', []),
STDMETHOD(HRESULT, 'GetChannelCount', []),
COMMETHOD([], HRESULT, 'SetMasterVolumeLevel',
(['in'], c_float, 'fLevelDB'),
(['in'], POINTER(GUID), 'pguidEventContext')
),
COMMETHOD([], HRESULT, 'SetMasterVolumeLevelScalar',
(['in'], c_float, 'fLevelDB'),
(['in'], POINTER(GUID), 'pguidEventContext')
),
COMMETHOD([], HRESULT, 'GetMasterVolumeLevel',
(['out','retval'], POINTER(c_float), 'pfLevelDB')
),
COMMETHOD([], HRESULT, 'GetMasterVolumeLevelScalar',
(['out','retval'], POINTER(c_float), 'pfLevelDB')
),
COMMETHOD([], HRESULT, 'SetChannelVolumeLevel',
(['in'], DWORD, 'nChannel'),
(['in'], c_float, 'fLevelDB'),
(['in'], POINTER(GUID), 'pguidEventContext')
),
COMMETHOD([], HRESULT, 'SetChannelVolumeLevelScalar',
(['in'], DWORD, 'nChannel'),
(['in'], c_float, 'fLevelDB'),
(['in'], POINTER(GUID), 'pguidEventContext')
),
COMMETHOD([], HRESULT, 'GetChannelVolumeLevel',
(['in'], DWORD, 'nChannel'),
(['out','retval'], POINTER(c_float), 'pfLevelDB')
),
COMMETHOD([], HRESULT, 'GetChannelVolumeLevelScalar',
(['in'], DWORD, 'nChannel'),
(['out','retval'], POINTER(c_float), 'pfLevelDB')
),
COMMETHOD([], HRESULT, 'SetMute',
(['in'], BOOL, 'bMute'),
(['in'], POINTER(GUID), 'pguidEventContext')
),
COMMETHOD([], HRESULT, 'GetMute',
(['out','retval'], POINTER(BOOL), 'pbMute')
),
COMMETHOD([], HRESULT, 'GetVolumeStepInfo',
(['out','retval'], POINTER(c_float), 'pnStep'),
(['out','retval'], POINTER(c_float), 'pnStepCount'),
),
COMMETHOD([], HRESULT, 'VolumeStepUp',
(['in'], POINTER(GUID), 'pguidEventContext')
),
COMMETHOD([], HRESULT, 'VolumeStepDown',
(['in'], POINTER(GUID), 'pguidEventContext')
),
COMMETHOD([], HRESULT, 'QueryHardwareSupport',
(['out','retval'], POINTER(DWORD), 'pdwHardwareSupportMask')
),
COMMETHOD([], HRESULT, 'GetVolumeRange',
(['out','retval'], POINTER(c_float), 'pfMin'),
(['out','retval'], POINTER(c_float), 'pfMax'),
(['out','retval'], POINTER(c_float), 'pfIncr')
),
]
class IMMDevice(IUnknown):
_iid_ = GUID('{D666063F-1587-4E43-81F1-B948E807363F}')
_methods_ = [
COMMETHOD([], HRESULT, 'Activate',
(['in'], POINTER(GUID), 'iid'),
(['in'], DWORD, 'dwClsCtx'),
(['in'], POINTER(DWORD), 'pActivationParans'),
(['out','retval'], POINTER(POINTER(IAudioEndpointVolume)), 'ppInterface')
),
STDMETHOD(HRESULT, 'OpenPropertyStore', []),
STDMETHOD(HRESULT, 'GetId', []),
STDMETHOD(HRESULT, 'GetState', [])
]
pass
class IMMDeviceEnumerator(comtypes.IUnknown):
_iid_ = GUID('{A95664D2-9614-4F35-A746-DE8DB63617E6}')
_methods_ = [
COMMETHOD([], HRESULT, 'EnumAudioEndpoints',
(['in'], DWORD, 'dataFlow'),
(['in'], DWORD, 'dwStateMask'),
(['out','retval'], POINTER(POINTER(IMMDeviceCollection)), 'ppDevices')
),
COMMETHOD([], HRESULT, 'GetDefaultAudioEndpoint',
(['in'], DWORD, 'dataFlow'),
(['in'], DWORD, 'role'),
(['out','retval'], POINTER(POINTER(IMMDevice)), 'ppDevices')
)
]
enumerator = comtypes.CoCreateInstance(
CLSID_MMDeviceEnumerator,
IMMDeviceEnumerator,
comtypes.CLSCTX_INPROC_SERVER
)
class volume_change:
def __init__(self):
print enumerator
self.endpoint = enumerator.GetDefaultAudioEndpoint( 0, 1 )
print self.endpoint
self.volume = self.endpoint.Activate( IID_IAudioEndpointVolume, comtypes.CLSCTX_INPROC_SERVER, None )
print self.volume
print self.volume.GetMasterVolumeLevel()
print self.volume.GetVolumeRange()
def set_volume(self,level):
self.volume.SetMasterVolumeLevel(level, None)
#vol = volume_change()
#vol.set_volume(-20.0)