-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolume.py
68 lines (56 loc) · 1.31 KB
/
volume.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python3
# pip3 install pyalsaaudio
# not for windows
import platform
if platform.uname()[0] == 'Windows':
exit()
try:
import alsaaudio
except ImportError:
exit()
import sys
m = alsaaudio.Mixer()
vol = m.getvolume()
def getVolume():
global vol
return vol[0]
def increase(n):
global vol
if (vol[0] + n)>100:
vol[0]= 100 - n
m.setvolume(vol[0] + n)
vol = m.getvolume()
print("Volume increased to " + str(vol[0]) + " percent")
def decrease(n):
global vol
if (vol[0] - n)>100:
vol[0]= 100 + n
m.setvolume(vol[0] - n)
vol = m.getvolume()
print("Volume decreased to " + str(vol[0]) + " percent")
def setVolume(n):
global vol
m.setvolume(n)
vol = m.getvolume()
print ("Volume set to " + str(vol[0]) + " percent")
if len(sys.argv) == 1 or sys.argv[1] == "g":
print("Current volume is " + str(getVolume()) + " percent")
if len(sys.argv)>=3:
if sys.argv[1] == "i":
try:
i = int(sys.argv[2])
increase(i)
except ValueError:
print("Please specify a number after saying increase volume by")
elif sys.argv[1] == "d":
try:
d = int(sys.argv[2])
decrease(d)
except:
print("Please specify a number after saying decrease volume by")
elif sys.argv[1] == "s":
try:
s = int(sys.argv[2])
setVolume(s)
except:
print ("Please specify a number after saying set volume to")