You are not logged in.

#1 2022-01-03 23:51:18

Matt_ArchLinux
Member
Registered: 2022-01-03
Posts: 3

No sound output for service using festival

I don't know if you can help me with this one because I am using festival for audio output. But I don't think it is a problem related to festival.

My goal is to have a service that auto starts a greeting script (greeting.sh) on startup. That script uses festival for a text to speech output.
I am using festival with pulseaudio configuration. The script I am using is the following:

 #!/bin/bash
  echo "Hello, World! It is good to see you!" | festival --tts --pipe

If I run it via the terminal it just works fine.

The content of my service file (located at /etc/systemd/system/welcome.service) is the following:

  [Unit]
  Description=Start greeting
  Requires=sound.target
  After=multi-user.target
   
  [Service]
  User=matt
  ExecStart=/home/matt/greeting.sh
   
  [Install]
  WantedBy=multi-user.target

However, If I enable the service and start it (no matter if sudo or not), there is no audio output and I get the following messages when I check the status of the service:

Loaded: loaded (/etc/systemd/system/welcome.service; enabled; vendor preset: disabled)
     Active: inactive (dead) since Tue 2022-01-04 00:42:28 CET; 5s ago
    Process: 130634 ExecStart=/home/matt/greetings.sh (code=exited, status=0/SUCCESS)
   Main PID: 130634 (code=exited, status=0/SUCCESS)
        CPU: 1.602s

Jan 04 00:42:26 archlinux systemd[1]: Started Start greeting.
Jan 04 00:42:27 archlinux greetings.sh[130674]: Connection failure: Connection refused
Jan 04 00:42:27 archlinux greetings.sh[130674]: pa_context_connect() failed: Connection refused
Jan 04 00:42:28 archlinux greetings.sh[130676]: Connection failure: Connection refused
Jan 04 00:42:28 archlinux greetings.sh[130676]: pa_context_connect() failed: Connection refused
Jan 04 00:42:28 archlinux systemd[1]: welcome.service: Deactivated successfully.
Jan 04 00:42:28 archlinux systemd[1]: welcome.service: Consumed 1.602s CPU time.

It seems like a permission problem to me but I don't know what the problem could be. Can anyone support me on this? Do you need any other information?
I apologize if I missed some important information. I am new to this forum and this is my first post.

Last edited by Matt_ArchLinux (2022-01-03 23:54:25)

Offline

#2 2022-01-05 21:11:08

TheStroyer
Member
Registered: 2018-08-28
Posts: 52

Re: No sound output for service using festival

It could be a problem with the service being started too early (before pulseaudio is ready). Could you post the output of the following command?

systemd-analyze --user critical-chain welcome.service

It could also be an issue with permissions. It strikes me that your service is located in /etc/systemd/system/ and it includes the User= keyword. This looks to me like it's not a proper user unit (which shouldn't need the User= keyword). You should put the service in /etc/systemd/user/ or .config/systemd/user and remove the User= keyword. After changing the unit, dont forget to run:

systemctl --user daemon-reload

Then to enable the service you can use:

systemctl --user enable welcome.service

Last edited by TheStroyer (2022-01-05 21:11:23)

Offline

#3 2022-01-10 19:04:10

Matt_ArchLinux
Member
Registered: 2022-01-03
Posts: 3

Re: No sound output for service using festival

Executing the command while the service file was located in the /etc/systemd/system folder (with the file unchanged) did not provide any information. Just like the service did not start at all (I ensured that it was enabled):

[matt@archlinux ~]$ systemd-analyze --user critical-chain welcome.service
The time when unit became active or started is printed after the "@" character.
The time the unit took to start is printed after the "+" character.

[matt@archlinux ~]$ 

However, I then moved the file to /etc/systemd/user and removed the User= keyword (reloading and enabling done). Then, I got the following output:

[matt@archlinux ~]$ systemd-analyze --user critical-chain welcome.service
The time when unit became active or started is printed after the "@" character.
The time the unit took to start is printed after the "+" character.

└─basic.target @72ms
  └─sockets.target @72ms
    └─dbus.socket @69ms +3ms
      └─app.slice @69ms
        └─-.slice @64ms
[matt@archlinux ~]$ 

But still there was no audio output.
If I try to manually start the service via command line, it says:

Failed to start welcome.service: Unit network.target not found.

Last edited by Matt_ArchLinux (2022-01-10 19:05:21)

Offline

#4 2022-01-10 19:09:24

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 15,039

Re: No sound output for service using festival

If set up as an user service you can do a dependency on pulseaudio, like so:

  [Unit]
  Description=Start greeting
  After=pulseaudio.service
   
  [Service]
  Type=oneshot
  ExecStart=/home/matt/greeting.sh
   
  [Install]
  WantedBy=default.target

Last edited by V1del (2022-01-10 19:10:09)

Offline

#5 2022-01-10 20:52:39

Matt_ArchLinux
Member
Registered: 2022-01-03
Posts: 3

Re: No sound output for service using festival

I have changed the file to your suggestion and now it works! smile

Thank you both very much!

Offline

Board footer

Powered by FluxBB