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?

  • I haven't used it personally, but if you want to do this programmatically there's python bindings for alsa lib. That should be available as a package on Raspbian -- I don't have a Raspbian pi running right now but I'd guess the package is pyalsaaudio (check with apt-cache search alsa | grep python). That will mean reading the API docs a bit, so not as easy as os.system().
    – goldilocks
    Oct 9, 2015 at 17:49

1 Answer 1

  1. Create a Bash file with the following code:

    amixer scontrols
    amixer sset 'Master' 50%
  2. Make the Bash file executable using chmod +x filename

  3. In Python, use the following:

    import os
  • alsamixer is a GUI, not a one line command to change volume. Oct 9, 2015 at 17:27
  • @PatrickCook I think I got alsamixer mixed up with amixer
    – Kachamenus
    Oct 9, 2015 at 17:33
  • @PatrickCook added the correct code for alsamixer
    – Kachamenus
    Oct 9, 2015 at 17:37
  • amixer scontrols just prints the list of controls. And why don't you execute amixer directly?
    – CL.
    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
    Oct 10, 2015 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.