Created
December 12, 2018 15:58
-
-
Save alifahrri/b44e024492c1418c4c29e310efce7840 to your computer and use it in GitHub Desktop.
control ubuntu audio volume from python
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
from subprocess import call | |
from time import sleep | |
from datetime import datetime | |
import argparse | |
if __name__ == '__main__' : | |
parser = argparse.ArgumentParser(progname='python vol-ctrl.py', description='decrease volume with delay') | |
parser.add_argument('-i','--init',type=int,help='initial volume') | |
parser.add_argument('-r','--rate',type=int,help='decrease rate') | |
parser.add_argument('-d','--delay',type=int,help='decrease delay in seconds') | |
args = parser.parse_args() | |
volume = 35 | |
decrease_rate = 5 | |
decrease_delay = 10 #seconds | |
if args.init : | |
volume = args.init | |
if args.rate : | |
decrease_rate = args.rate | |
if args.delay : | |
decrease_delay = args.delay | |
cmd = ['pactl','set-sink-volume','@DEFAULT_SINK@','%s%%'%volume] | |
while volume > 0 : | |
vol = volume | |
for i in range(decrease_rate) : | |
vol = vol - 1 | |
cmd[-1] = '%s%%'%vol | |
call(cmd) | |
print(datetime.now().strftime("%Y-%m-%d %H:%M") + ' volume : '+cmd[-1]) | |
sleep(1) | |
volume = vol | |
sleep(decrease_delay) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment