1

You can change the master volume within the terminal itself by using the command shown underneath.

amixer -D pulse sset Master 5%+

However, when I tried to execute the following code in Python, the following error is shown.

No protocol specified
xcb_connection_has_error() returned true
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

amixer: Mixer attach pulse error: Connection refused

And here is the code producing the error above.

os.system("amixer -D pulse sset Master 5%+")

How does one resolve that error?

  • The "unable to connect" error can mean: pulseaudio is not running or permissions issues exist. "pactl" may be more appropriate for controlling pulseaudio. Try determine what output you're trying to control by running: "pactl list sinks". Review the output of that command to determine the sink number. Then run something like "pactl set-sink-volue 3 +5%" (where "3" is the sink # on my machine for "Built-in Audio Analog Stereo"). One point to note: sink numbers can change across reboots, so it is worthwhile to research how to accomplish the same thing with sink names instead of sink numbers. – joat Jan 26 '19 at 13:55
  • I have tried pactl also but getting same errors.@joat – Ghatak Sena Jan 26 '19 at 13:57
  • Pulseaudio is running? Are you (or your script) running pactl/amixer as the logged in user (not root)? That's about all that I can think of. – joat Jan 26 '19 at 14:14
  • Of course it's working in terminal but my main issue is that it's not working with Python code.@joat – Ghatak Sena Jan 26 '19 at 14:21
  • It's must be a permissions issue. 'import os;os.system("pactl set-sink-mute 3 1")' works if I run it in a terminal or in a script. When you run amixer, do you have to select the sound card before doing anything else? – joat Jan 26 '19 at 23:10
0

Finally, I got a solution to my own problem which is shown below

    import subprocess
    proc = subprocess.Popen('/usr/bin/amixer sset Master 5%', shell=True, stdout=subprocess.PIPE)
    proc.wait()
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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