[Never Mind] Control sound amplitude from a bash script

[Never Mind] Control sound amplitude from a bash script

Postby mark9117 » Jan 27th, '17, 02:46

Linux adamsmdk 4.4.39-desktop-1.mga5 #1 SMP Fri Dec 16 18:43:46 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
pulseaudio 5.0.0-6.mga5

Greetings!

Hope this finds all here well. I have an issue that I can't seem to get a handle on. I have a Bash script fired by a cron job that uses mplayer to play a playlist. I would like to write a line into that script that sets playback volume.

The system uses Pulseaudio, so it seems the alsa commands don't work:

Code: Select all
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

cannot open mixer: Connection refused


I looked into the "pactl" command, but that seems out of the question as well.

Code: Select all
$ pactl info Connection failure: Connection refused
pa_context_connect() failed: Connection refused


I thought this was because Pulseaudio wasn't running as a daemon, so I tried reconfiguring the pulse/client.conf and pulse/daemon.conf files to get that to happen. I then found that there's no way to stop Pulseaudio. I set autospawn=no but was still unable to stop it with "pulseaudio -k" or even by killing the process running pulseaudio. So I rebooted. That didn't help anything. The daemon would not start and audio was broken.

Rather than work on that, I just backed those changes out and got sound working again.

Now, I'm seeking help. Is there a way to do this?

What am I missing?

Thanks.
Last edited by mark9117 on Jan 28th, '17, 05:39, edited 1 time in total.
Let's just reboot everything all the time.
User avatar
mark9117
 
Posts: 383
Joined: Sep 12th, '11, 20:32
Location: Eastern New Mexico -- Not Hell, but you can see it from here.

Re: Control sound amplitude from a bash script

Postby doktor5000 » Jan 27th, '17, 20:29

You're missing basic information like under which user the script runs ...

You may also want to take a look at a previous thread with a similar issue for some pointers: viewtopic.php?f=26&t=6453
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 14495
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Control sound amplitude from a bash script

Postby mark9117 » Jan 28th, '17, 05:38

Okay, never mind. It seems the argument "-volume n" where "n" is an integer from 0-100 works with mplayer. I wasn't able to get that work when I originally wrote up this script, but it works now. Also, having issues working around Pulseaudio. I'm pretty sure Pulse led me to think the volume argument didn't work in mplayer in the first place. The Pulseaudio installation on this machine is not solid. I can't use some of the other tools that are supposed to be available with Pulse (pactl, pacmd, etc.)

At any rate, for now I'm sorted.
Let's just reboot everything all the time.
User avatar
mark9117
 
Posts: 383
Joined: Sep 12th, '11, 20:32
Location: Eastern New Mexico -- Not Hell, but you can see it from here.

Re: Control sound amplitude from a bash script

Postby doktor5000 » Jan 28th, '17, 12:38

mark9117 wrote:I can't use some of the other tools that are supposed to be available with Pulse (pactl, pacmd, etc.)

That is because you need an active login session where also a udev session is running, which is not the case when calling those from a cronjob as cron only provides a rather minimal environment.
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 14495
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Control sound amplitude from a bash script

Postby mark9117 » Jan 28th, '17, 17:45

doktor5000 wrote:
mark9117 wrote:I can't use some of the other tools that are supposed to be available with Pulse (pactl, pacmd, etc.)

That is because you need an active login session where also a udev session is running, which is not the case when calling those from a cronjob as cron only provides a rather minimal environment.


I'm saying I can't get those tools to work in an ssh session at any time. I'm not trying to use those tools in a cron job. The tools are not available to my regular user or root. Given that Pulseaudio seems network oriented, I would assume I could use those tools remotely. I have identified the server in /etc/pulse/client.conf: default-server = {e4d5f7dba70d45e38519331400b16c34}unix:/run/user/10001/pulse/native, but I still have troubles.

Also notice that the server identified is not actually my regular user, it's the default user that installs when you run the live DVD/CD. I have changed ownership of that user to my regular user, but I don't know if that avoids issues. For all I know, it may be a bad thing.

I think I could discover more if I could get pulseaudio to run as a daemon, but that doesn't happen.

Code: Select all
[root@adamsmdk 10001]# pacmd
No PulseAudio daemon running, or not running as session daemon.
[root@adamsmdk 10001]# ps aux|grep pulseaudio
madams    3108  0.0  0.4 371904  8420 ?        S<sl Jan27   0:37 /usr/bin/pulseaudio


So, I don't know.
Let's just reboot everything all the time.
User avatar
mark9117
 
Posts: 383
Joined: Sep 12th, '11, 20:32
Location: Eastern New Mexico -- Not Hell, but you can see it from here.

Re: [Never Mind] Control sound amplitude from a bash script

Postby doktor5000 » Jan 28th, '17, 21:02

You're mixing things up quite a bit, in the beginning you only mentioned a bash script. Now it's via ssh, and you don't even mention some context for this.
For ssh you would at least need X forwarding enabled, as some of the pulse properties are added to the X cookie. But you don't even mentioned whether you want to transport sound via the ssh session, and from where you connect to where and where pulse is running.

Apart from that, you cannot query your user pulse session as root, pacmd also clearly tells this - the pulse session is running for user madams.
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 14495
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: [Never Mind] Control sound amplitude from a bash script

Postby mark9117 » Jan 28th, '17, 23:21

I'm trying to manage a headless media server. I'm managing it over ssh. The media server is using pulseaudio and alsa to handle audio. I can't get pulseaudio to run as a daemon on the server. If I deviate just a little from my current configuration, pulseaudio fails to connect and I get no audio from the server.

At this point, I believe I have a system that works to my satisfaction - a cron job fires MPlayer which plays a Playlist file selected at random from a list of Playlist files at a volume determined on the command line. I can also use my iPad to control a VLC instance and play a list of files at bedtime at a volume set in the remote VLC client..

I just wished that I had a better handle on pulseaudio because it seems to get in the way when it comes to making changes in the automated execution of audio.

Ideally, when I'm done with this I can get it to read aloud the date, time, weather and headlines after the music has played. For someone who is not a coder, it's a challenge.
Let's just reboot everything all the time.
User avatar
mark9117
 
Posts: 383
Joined: Sep 12th, '11, 20:32
Location: Eastern New Mexico -- Not Hell, but you can see it from here.


Return to Sound

Who is online

Users browsing this forum: No registered users and 1 guest

cron