Установите Python и получите громкость Windows 11Python

Программы на Python
Ответить
Anonymous
 Установите Python и получите громкость Windows 11

Сообщение Anonymous »

У меня есть этот скрипт:

Код: Выделить всё

from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL, CoInitialize, CoUninitialize
CLSCTX_ALL = 7

import time

def set_windows_volume(value_max_100):
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
scalarVolume = int(value_max_100) / 100
volume.SetMasterVolumeLevelScalar(scalarVolume, None)

def get_windows_volume():
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
windows_volume = cast(interface, POINTER(IAudioEndpointVolume))
volume_percentage = int(round(windows_volume.GetMasterVolumeLevelScalar() * 100))
return volume_percentage

for i in range(0,100):
set_windows_volume(i)
time.sleep(2)
print(get_windows_volume())
но иногда возникают ошибки:

Код: Выделить всё

Exception ignored in: 
Traceback (most recent call last):
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 426, in __del__
self.Release()
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 559, in Release
return self.__com_Release()  # type: ignore
ValueError: COM method call without VTable
Exception ignored in: 
Traceback (most recent call last):
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 426, in __del__
self.Release()
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 559, in Release
return self.__com_Release()  # type: ignore
ValueError: COM method call without VTable
Exception ignored in: 
Traceback (most recent call last):
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 426, in __del__
self.Release()
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 559, in Release
return self.__com_Release()  # type: ignore
ValueError: COM method call without VTable
Exception ignored in: 
Traceback (most recent call last):
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 426, in __del__
self.Release()
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 559, in Release
return self.__com_Release()  # type: ignore
ValueError: COM method call without VTable
Exception ignored in: 
Traceback (most recent call last):
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 426, in __del__
self.Release()
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 559, in Release
return self.__com_Release()  # type: ignore
ValueError: COM method call without VTable
Exception ignored in: 
Traceback (most recent call last):
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 426, in __del__
self.Release()
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 559, in Release
return self.__com_Release()  # type: ignore
ValueError: COM method call without VTable
Exception ignored in: 
Traceback (most recent call last):
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 426, in __del__
self.Release()
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 559, in Release
return self.__com_Release()  # type: ignore
ValueError: COM method call without VTable
Exception ignored in: 
Traceback (most recent call last):
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 426, in __del__
self.Release()
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 559, in Release
return self.__com_Release()  # type: ignore
ValueError:  COM method call without VTable
Exception ignored in: 
Traceback (most recent call last):
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 426, in __del__
self.Release()
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 559, in Release
return self.__com_Release()  # type: ignore
ValueError: COM method call without VTable
Exception ignored in: 
Traceback (most recent call last):
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 426, in __del__
self.Release()
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 559, in Release
return self.__com_Release()  # type: ignore
ValueError: COM method call without VTable
======== Running on http://192.168.1.188:8080 ========
Exception ignored in: 
Traceback (most recent call last):
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 426, in __del__
self.Release()
File "C:\Python\lib\site-packages\comtypes\_post_coinit\unknwn.py", line 559, in Release
return self.__com_Release()  # type: ignore
ValueError: COM method call without VTable
В основном я использую этот скрипт в многопроцессорном процессе с CoInitialize и CoUninitialize и безопасным выпуском, но ошибка все еще существует.
Любая помощь или альтернативы?

Подробнее здесь: https://stackoverflow.com/questions/792 ... -11-volume
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»