I need to change my volume on my USB sound card (which is the default card) via the command line. I know alsamixer
will do that but I need it to be a one line command so I can use it in a python script, e.g., os.system("volume up 1")
, or something like that. Is there any way to do this?
goldilocks
60.4k17 gold badges117 silver badges236 bronze badges
asked Oct 9, 2015 at 17:12
1 Answer 1
Create a Bash file with the following code:
amixer scontrols amixer sset 'Master' 50%
Make the Bash file executable using
chmod +x filename
In Python, use the following:
import os os.system("directorytobashfile/file")
Bex
2,9293 gold badges27 silver badges34 bronze badges
answered Oct 9, 2015 at 17:17
-
alsamixer
is a GUI, not a one line command to change volume.Patrick Cook– Patrick Cook2015年10月09日 17:27:38 +00:00Commented Oct 9, 2015 at 17:27 -
@PatrickCook I think I got
alsamixer
mixed up withamixer
Kachamenus– Kachamenus2015年10月09日 17:33:23 +00:00Commented Oct 9, 2015 at 17:33 -
@PatrickCook added the correct code for
alsamixer
Kachamenus– Kachamenus2015年10月09日 17:37:02 +00:00Commented Oct 9, 2015 at 17:37 -
amixer scontrols
just prints the list of controls. And why don't you executeamixer
directly?CL.– CL.2015年10月10日 08:09:27 +00:00Commented Oct 10, 2015 at 8:09 -
@CL. Sorry I just do that to make sure I have the right command. I don't execute it directly because this way he can add to the bash file. You could do it directly too!Kachamenus– Kachamenus2015年10月10日 15:42:51 +00:00Commented Oct 10, 2015 at 15:42
pyalsaaudio
(check withapt-cache search alsa | grep python
). That will mean reading the API docs a bit, so not as easy asos.system()
.