I'm writing a program to control my system volume either increase or decrease in voice command. but I don't know how and what are all the packages should to be installed? I'm using python 3.7.0 in pycharm
Using Python to control system audio i [Voice Control]
613 Views Asked by Rafiyudheen Rafi At
2
There are 2 best solutions below
0
On
I found something interesting on https://techoverflow.net/2020/04/04/how-to-set-windows-audio-volume-using-python/ but this only works for Windows.
The package they are using is pycaw. You can install it with
pip install pycaw.
That is the script on the website:
from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
import math
# Get default audio device using PyCAW
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(
IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
# Get current volume
currentVolumeDb = volume.GetMasterVolumeLevel()
volume.SetMasterVolumeLevel(currentVolumeDb - 6.0, None)
# NOTE: -6.0 dB = half volume !
If I use
volume.SetMasterVolumeLevel(-65.25, None)
my system volume is set to 0
and with
volume.SetMasterVolumeLevel(0, None)
I can set the system volume to 100
I am not sure but u can probably use tkinter. I had created a duplication GUI file so just copy this code and paste in python:
so if u see i have typed exe extension after file name in the function. Try typing all ur code in a notepad and then convert to exe from this file(after pasting the code save the file and run it), u can do that from changing extension but u should make copy too, anyway this file's code was only for ur reference and btw the copy file will be in pycharm only, if u use it for python IDLE like me it will come in file explorer. convert a notepad file from this by duplicating the file and then go back, type ur code for the volume and use this code at the end for the code to control volume:
so the data should be read and work, i hope it does cuz it works for me, in other projects.