-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
229 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Make sure to give enough information to help debugging your issue. | ||
Here are some hints: | ||
|
||
- current requirements (pip freeze) | ||
- OS version | ||
- architecture | ||
- Python version | ||
- pycaw version | ||
- project files | ||
- exact stacktrace / accurate error message | ||
- and so on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# Custom | ||
venv/ | ||
*.swp | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
os: windows | ||
|
||
language: shell | ||
|
||
before_install: | ||
- choco install python3 --version 3.6.7 | ||
- export PATH="/c/Python36:/c/Python36/Scripts:$PATH" | ||
|
||
install: | ||
- python -m pip install -r requirements.txt | ||
- python -m pip install tox-travis | ||
|
||
script: | ||
- tox -e pep8 | ||
- tox -e isort | ||
# can't run actual unit tests on Travis | ||
# https://travis-ci.org/AndreMiras/pycaw/builds/472124432 | ||
# _ctypes.COMError: (-2147023174, 'The RPC server is unavailable.', (None, None, None, 0, None)) | ||
# - tox -e py36 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
""" | ||
Per session GetMute() SetMute() GetMasterVolume() SetMasterVolume() using | ||
SimpleAudioVolume. | ||
""" | ||
from __future__ import print_function | ||
|
||
from pycaw.pycaw import AudioUtilities | ||
|
||
|
||
class AudioController(object): | ||
def __init__(self, process_name): | ||
self.process_name = process_name | ||
self.volume = self.process_volume() | ||
|
||
def mute(self): | ||
sessions = AudioUtilities.GetAllSessions() | ||
for session in sessions: | ||
interface = session.SimpleAudioVolume | ||
if session.Process and session.Process.name() == self.process_name: | ||
interface.SetMute(1, None) | ||
print(self.process_name, 'has been muted.') # debug | ||
|
||
def unmute(self): | ||
sessions = AudioUtilities.GetAllSessions() | ||
for session in sessions: | ||
interface = session.SimpleAudioVolume | ||
if session.Process and session.Process.name() == self.process_name: | ||
interface.SetMute(0, None) | ||
print(self.process_name, 'has been unmuted.') # debug | ||
|
||
def process_volume(self): | ||
sessions = AudioUtilities.GetAllSessions() | ||
for session in sessions: | ||
interface = session.SimpleAudioVolume | ||
if session.Process and session.Process.name() == self.process_name: | ||
print('Volume:', interface.GetMasterVolume()) # debug | ||
return interface.GetMasterVolume() | ||
|
||
def set_volume(self, decibels): | ||
sessions = AudioUtilities.GetAllSessions() | ||
for session in sessions: | ||
interface = session.SimpleAudioVolume | ||
if session.Process and session.Process.name() == self.process_name: | ||
# only set volume in the range 0.0 to 1.0 | ||
self.volume = min(1.0, max(0.0, decibels)) | ||
interface.SetMasterVolume(self.volume, None) | ||
print('Volume set to', self.volume) # debug | ||
|
||
def decrease_volume(self, decibels): | ||
sessions = AudioUtilities.GetAllSessions() | ||
for session in sessions: | ||
interface = session.SimpleAudioVolume | ||
if session.Process and session.Process.name() == self.process_name: | ||
# 0.0 is the min value, reduce by decibels | ||
self.volume = max(0.0, self.volume-decibels) | ||
interface.SetMasterVolume(self.volume, None) | ||
print('Volume reduced to', self.volume) # debug | ||
|
||
def increase_volume(self, decibels): | ||
sessions = AudioUtilities.GetAllSessions() | ||
for session in sessions: | ||
interface = session.SimpleAudioVolume | ||
if session.Process and session.Process.name() == self.process_name: | ||
# 1.0 is the max value, raise by decibels | ||
self.volume = min(1.0, self.volume+decibels) | ||
interface.SetMasterVolume(self.volume, None) | ||
print('Volume raised to', self.volume) # debug | ||
|
||
|
||
def main(): | ||
audio_controller = AudioController('chrome.exe') | ||
audio_controller.set_volume(1.0) | ||
audio_controller.mute() | ||
audio_controller.decrease_volume(0.25) | ||
audio_controller.increase_volume(0.05) | ||
audio_controller.unmute() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
IAudioEndpointVolumeCallback.OnNotify() example. | ||
The OnNotify() callback method gets called on volume change. | ||
""" | ||
from __future__ import print_function | ||
|
||
from ctypes import POINTER, cast | ||
|
||
from comtypes import CLSCTX_ALL, COMObject | ||
|
||
from pycaw.pycaw import (AudioUtilities, IAudioEndpointVolume, | ||
IAudioEndpointVolumeCallback) | ||
|
||
|
||
class AudioEndpointVolumeCallback(COMObject): | ||
_com_interfaces_ = [IAudioEndpointVolumeCallback] | ||
|
||
def OnNotify(self, pNotify): | ||
print('OnNotify callback') | ||
|
||
|
||
def main(): | ||
devices = AudioUtilities.GetSpeakers() | ||
interface = devices.Activate( | ||
IAudioEndpointVolume._iid_, CLSCTX_ALL, None) | ||
volume = cast(interface, POINTER(IAudioEndpointVolume)) | ||
callback = AudioEndpointVolumeCallback() | ||
volume.RegisterControlChangeNotify(callback) | ||
for i in range(3): | ||
volume.SetMute(0, None) | ||
volume.SetMute(1, None) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
comtypes==1.1.2 | ||
comtypes==1.1.3.post2 | ||
enum34==1.1.4 | ||
psutil==4.1.0 | ||
psutil==5.4.8 | ||
future==0.15.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
flake8==2.5.4 | ||
isort==4.3.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters