Closed lastochka364 closed 1 year ago
One way to fix that is to download the api
folder from https://github.com/AndreMiras/pycaw/tree/develop/pycaw and then put that folder in C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python39\Lib\site-packages\pycaw
The reason why it gives you error says No module named
pycaw.api` is because in that pycaw folder there no folder called api
Since more than year, I found that still opened.
pycaw==20220416
correctly gives me access to method GetMicrophone()
:
from comtypes import CLSCTX_ALL, COMObject
from pycaw.pycaw import (AudioUtilities, IAudioEndpointVolume,
IAudioEndpointVolumeCallback)
class MicrophoneController(AudioUtilities):
'''
This controller uses "pycaw" module to operate with microphone states.
Initalizate connection to default microphone in system if any available.
'''
def __init__(self):
self.__mic = cast(self.GetMicrophone().Activate(\
IAudioEndpointVolume._iid_, CLSCTX_ALL, None),\
POINTER(IAudioEndpointVolume))
def mute_mic(self):
'''Mutes system microphone.'''
self.__mic.SetMute(True, None)
def unmute_mic(self):
'''Unmutes system microphone.'''
self.__mic.SetMute(False, None)
...
Thanks for such amazing project!
General Info:
This message appears when installing pycaw using "pip install pycaw" and trying to get microphone: "AttributeError: type object 'AudioUtilities' has no attribute 'GetMicrophone'".
However, in dev version (pip install https://github.com/AndreMiras/pycaw/archive/develop.zip) error message is different. It's related on imports - when I'm trying to import AudioUtilities from pycaw.pycaw, this appears: from pycaw.api.audioclient import IAudioClient, ISimpleAudioVolume ModuleNotFoundError: No module named 'pycaw.api'.
The most interesting, that file "pycaw/utils.py", which now on github repo, has "GetMicrophone" method. Of course, I have already solved this - simply by pasting missing mehod in "Python\Lib\site-packages\pycaw.py" file, but that still a problem.