You are not logged in.

#1 2016-01-10 10:20:11

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

[SOLVED] How to make systemd play a sound (via espeak)?

Hi everybody,

I am trying to build an acoustic reminder to plug in the power cord on my DELL E5550 notebook if the battery level becomes critically low. A systemd timer seems to be the perfect way to achieve this, so according to the arch wiki article I wrote a service file /usr/lib/systemd/system/reportlowbattery.service:

[Unit]
Description=ReportLowBattery

[Service]
Type=simple
ExecStart=/usr/local/bin/reportlowbattery.sh

accompanied by the timer file /usr/lib/systemd/system/reportlowbattery.timer:

[Unit]
Description=user defined timer that checks battery status every minute

[Timer]
OnCalendar=minutely

[Install]
WantedBy=multi-user.target

to run the script (executable by root and shortend to the relevant part) /usr/local/bin/reportlowbattery.sh:

#!/bin/bash
if [ 1 -eq 1 ] # for testing
then
	/usr/bin/espeak -vde 'plug in power cord'
fi

Starting the timer with "sudo systemctl start reportlowbattery.timer", it seems to run as it sould, since "systemctl status reportbattery.timer" yields

● reportlowbattery.timer - user defined timer that checks battery status every minute
   Loaded: loaded (/usr/lib/systemd/system/reportlowbattery.timer; disabled; vendor preset: disabled)
   Active: active (waiting) since Sun 2016-01-10 10:35:51 CET; 3s ago

Jan 10 10:35:51 klapperkiste systemd[1]: Started user defined timer that checks battery status every minute.

According to "journalctl" the is fired every minute as expected, yet no sound can be heard. The script outputs sound when run as root and when run as a non-root user. The usual system sound works perfectly normal as well.

journalctl does print a bunch of messages when systemd tries to start the timer; these are the first few lines:

systemd[1]: Started ReportLowBattery.
reportlowbattery.sh[1331]: ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
reportlowbattery.sh[1331]: ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
reportlowbattery.sh[1331]: ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
reportlowbattery.sh[1331]: ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
reportlowbattery.sh[1331]: ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
reportlowbattery.sh[1331]: ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
reportlowbattery.sh[1331]: ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
reportlowbattery.sh[1331]: connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
reportlowbattery.sh[1331]: attempt to connect to server failed
reportlowbattery.sh[1331]: Expression 'paInvalidSampleRate' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2043

The identical setup ran flawlessly on my old notebook (a lenovo), so everything ought to be all right with the service and time file (just as "systemctl status ..." suggests). On my lenovo I didn't get the "pcm_dsnoop.c:606" and "pcm_dmix.c:1029" messages.

I was able to solve "pcm_dsnoop.c:606..." by editing "/usr/share/alsa/cards/HDA-Intel.conf" and replacing "dsnoop" with "hw" at

	capture.pcm {
		type plug
		slave.pcm {
			type softvol
			slave.pcm {
				@func concat
				strings [ "dsnoop:" $CARD ]

I am not sure whether this is the correct approach to addressing this dsnoop issue.

I tried running the timer as my everyday user by including "User=delta" in the Service section of the service file but without success. Same thing for including "User=%i". For this test, my script was executable for everybody (systemd complained otherwise, so it indeed tired to run my script).

Although I searched extensively at the arch wiki, the forum, and at google, I can't find a solution to this issue, though I expect the solution to be simple. I am quite new at arch linux, but I managed to setup the timer on my old notebook just fine. Now I am surprised at how much of an issue this evolved to be with my new dell notebook.

Next to alsa, I have alsa-utils, pulseaudio, and pulseaudio-alsa installed.

I'd appreciate it if someone could give me any pointers on how to get things working.

Some additional info:
Output of "aplay -l":

**** List of PLAYBACK Hardware Devices ****
card 0: HDMI [HDA Intel HDMI], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 0: ALC3235 Analog [ALC3235 Analog]
  Subdevices: 1/1

Output of "aplay -L":

null
    Discard all samples (playback) or generate zero samples (capture)
pulse
    PulseAudio Sound Server
hdmi:CARD=HDMI,DEV=0
    HDA Intel HDMI, HDMI 0
    HDMI Audio Output
hdmi:CARD=HDMI,DEV=1
    HDA Intel HDMI, HDMI 1
    HDMI Audio Output
hdmi:CARD=HDMI,DEV=2
    HDA Intel HDMI, HDMI 2
    HDMI Audio Output
sysdefault:CARD=PCH
    HDA Intel PCH, ALC3235 Analog
    Default Audio Device
front:CARD=PCH,DEV=0
    HDA Intel PCH, ALC3235 Analog
    Front speakers
surround21:CARD=PCH,DEV=0
    HDA Intel PCH, ALC3235 Analog
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=PCH,DEV=0
    HDA Intel PCH, ALC3235 Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=PCH,DEV=0
    HDA Intel PCH, ALC3235 Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=PCH,DEV=0
    HDA Intel PCH, ALC3235 Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=PCH,DEV=0
    HDA Intel PCH, ALC3235 Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=PCH,DEV=0
    HDA Intel PCH, ALC3235 Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers

Edit: Marked as [SOLVED].

Last edited by fromminttoarch (2016-01-11 11:49:01)

Offline

#2 2016-01-11 11:47:55

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

Re: [SOLVED] How to make systemd play a sound (via espeak)?

I finally found the solution! smile

Apparently, changing the global ALSA configuration by replacing the contents of /etc/asound.conf with

pcm.!default {
    type hw
    card HDMI
}

ctl.!default {
    type hw
    card HDMI
}

works.

(I already tried the same thing with its local counterpart ~/.asoundrc without success.)

The remaining messages from journalctl ("Unknown PCM cards.pcm.rear" etc.) can easily be redirected to /dev/null by replacing the espeak line with in /usr/local/bin/reportlowbattery.sh with

/usr/bin/espeak -ven 'battery' 2>/dev/null

Marked as solved.

Offline

Board footer

Powered by FluxBB