You are not logged in.

#1 2016-01-12 10:07:23

fromminttoarch
Member
From: Germany
Registered: 2015-10-25
Posts: 14

[SOLVED] Make a systemd timer play sound if other applications do too

Hi everybody,

I recently figured out how to make a systemd timer play a sound with espeak. As it turns out, this works only if no other application (audacious in my case) is playing sound already.

I tired to pipe espeak to aplay without success. The same goes for paplay. For both cases, I specified various devices for (p)aplay but to no avail. I suspect things to be connected to the dmix plugin. But after reading tons of articles on alsa and pulseaudio, I still can't figure out how to solve this. Interestingly, though, whatever I tried does indeed work outside my systemd timer. That is, I can play sound simultaneously with audacious and aplay/espeak/paplay without any trouble. So it seems to be connected to systemd. Running my timer as User=fromminttoarch does not produce the desired result, either.

Sound ouput of systemd works as soon as I close audacious.

Can someone give me any pointers on how to proceed?

Edit: Marked as [SOLVED].

Last edited by fromminttoarch (2016-01-12 13:10:08)

Offline

#2 2016-01-12 10:15:42

tom.ty89
Member
Registered: 2012-11-15
Posts: 896

Re: [SOLVED] Make a systemd timer play sound if other applications do too

It's because you're trying to grab the device directly (type hw) in your /etc/asound.conf. Make it use dmix / pulse like audacious does (and make audacious does that too if it's actually grabbing the device as well).

Offline

#3 2016-01-12 10:25:07

fromminttoarch
Member
From: Germany
Registered: 2015-10-25
Posts: 14

Re: [SOLVED] Make a systemd timer play sound if other applications do too

Thanks for your reply tom.ty89!

I replaced /etc/asound.conf with the preinstalled one:

# Use PulseAudio by default
pcm.!default {
  type pulse
  fallback "sysdefault"
  hint {
    show on
    description "Default ALSA Output (currently PulseAudio Sound Server)"
  }
}

ctl.!default {
  type pulse
  fallback "sysdefault"
}

# vim:set ft=alsaconf:

Unfortunately, this did not change things. The script only works with "/usr/bin/espeak -ven 'test test'   | paplay" as long as audacious is closed. Otherwise I get "ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave".

Do you think I should use "pcm.!default {  type dmix" instead of "pcm.!default {  type pulse"?

Offline

#4 2016-01-12 10:29:36

tom.ty89
Member
Registered: 2012-11-15
Posts: 896

Re: [SOLVED] Make a systemd timer play sound if other applications do too

If you have PulseAudio running, all you need to do is to make audacious use its Pulse audio output, since espeak supports pulse natively. You don't even need this conf or the ALSA pulse plugin at all.

Offline

#5 2016-01-12 10:35:42

fromminttoarch
Member
From: Germany
Registered: 2015-10-25
Posts: 14

Re: [SOLVED] Make a systemd timer play sound if other applications do too

Audacious already uses its Pulse audio ouput. Since espeak supports pulse, I am at a loss why getting my timer to play both espeak and audacious output together is so difficult. Especially since it works directly without any trouble when I use espeak from the terminal. I wonder what systemd does differently.

Offline

#6 2016-01-12 10:38:37

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 12,240

Re: [SOLVED] Make a systemd timer play sound if other applications do too

I'd assume the systemd service lacks the environment to use pulse directly. Can you try using an actual systemd user service? Eventually you will have to import the environment using one of the described methods in the article or set the environment within the service file (To be more specific, you will likely need to pass the PULSE_COOKIE and/or PULSE_SERVER=localhost to its environment)

Last edited by V1del (2016-01-12 10:51:18)

Offline

#7 2016-01-12 11:25:25

fromminttoarch
Member
From: Germany
Registered: 2015-10-25
Posts: 14

Re: [SOLVED] Make a systemd timer play sound if other applications do too

Thanks for the hint, V1del!

Unfortunately I am unfamiliar with systemd user services. Following the wiki article you pointed me at, I created ~/.config/systemd/user and moved my service and timer files there (previously at /usr/lib/systemd/system/). Then I executed (as non-root) "systemctl --user enable reportlowbattery.timer" (which did not print the usual "Created symlink from..." line) and logged out and in again. "systemctl status reportlowbattery.timer" now yields

● reportlowbattery.timer
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)

Did I miss something?

Also: If I want this timer to be run for every user, do I then put the timer files at /etc/systemd/user/ ?

Edit: Added that enabling the timer did not create a symlink.

Last edited by fromminttoarch (2016-01-12 11:37:30)

Offline

#8 2016-01-12 12:21:25

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 12,240

Re: [SOLVED] Make a systemd timer play sound if other applications do too

you have to query the status with --user as well wink yes, to enable it for every user you would put it there

Offline

#9 2016-01-12 12:54:31

fromminttoarch
Member
From: Germany
Registered: 2015-10-25
Posts: 14

Re: [SOLVED] Make a systemd timer play sound if other applications do too

All right -- it works! smile

Thank you V1del for suggesting the systemd user service!

I just had to remove the "USER=..." line from my service file since this is now obsolete. Now my systemd-user-service-espeak can chime in with audacious. smile

For some reason enabling the service doesn't work (yet). I can start the service and it works. I can enable it and a symlink is created. But when I re-login, it's incative (dead). What went wrong with enabling it?

Time to read the systemd/user article:

systemd/User wrote:

When systemd user instance starts, it brings up the target default.target

So I used default.target instead of multi-user.target. Doing!

Problem solved.  With hindsight this was pretty staightforward.

Marked as [SOLVED].


Thanks everybody for your time and effort! smile

Last edited by fromminttoarch (2016-01-12 14:03:05)

Offline

Board footer

Powered by FluxBB