# "node-red-contrib-play-sound" fails in node-red on miniPC started from systemd service

**URL:** https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624
**Category:** General
**Created:** [6 October 2022 00:33 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624 "2022-10-06T00:33:18Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![fip](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@fip](https://discourse.nodered.org/u/fip)
#### Post date: [6 October 2022 00:33 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/1 "2022-10-06T00:33:18Z")

</div>

hi @zenofmud ,  
This is cool isn't it. I my self built also something like this. I was using a miniPC. I used mplayer to play mp3 files from nodered ui.  
But I have still an unsolved problem regarding the setup. I have very little knowledge of this nodejs/nodered stuff.

My problem is if node-red was started from systemd service, this "node-red-contrib-play-sound" failed to produce sound with this message in the logs:

```auto
5 Oct 19:09:19 - [info] [PlaySound:bc151945aaf7784e] Event input: /home/mine/song/003 .mp3
5 Oct 19:09:19 - [info] [PlaySound:bc151945aaf7784e] Play: /home/mine/song/003.mp3
5 Oct 19:09:19 - [info] [PlaySound:bc151945aaf7784e] Event exit:0, null

```

But if I started node-red with `$ node-red` from the shell the play-sound node will work fine.

Maybe you could share your thoughts to help me on this?

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [6 October 2022 00:47 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/2 "2022-10-06T00:47:36Z")

</div>

That first line shows a space between the `003` and the `.mp3` where is that coming from?

The fact you’re using a minipc and having a issue based on the way you start NR really doesn’t have anything to do with this project so I’m going to move your question to a new thread.

---

<div class="post-metadata">

### Author: ![fip](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@fip](https://discourse.nodered.org/u/fip)
#### Post date: [6 October 2022 07:39 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/3 "2022-10-06T07:39:07Z")

</div>

hi @zenofmud

> [@zenofmud](#):
>
> That first line shows a space between the `003` and the `.mp3` where is that coming from?

... that was just my typo when I edited the messages for the post here.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 October 2022 08:57 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/4 "2022-10-06T08:57:10Z")

</div>

> [@fip](#):
>
> But if I started node-red with `$ node-red` from the shell the play-sound node will work fine.

What do you see in the terminal when you start node-red from the shell and it plays correctly?

---

<div class="post-metadata">

### Author: ![fip](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@fip](https://discourse.nodered.org/u/fip)
#### Post date: [7 October 2022 02:05 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/5 "2022-10-07T02:05:49Z")

</div>

hi @Colin , here is the screen just from the node-red manual start and to the time when I play the mp3 with mplayer using "node-red-contrib-play-sound".  
It's playing for about 7-8 minutes and then the sound stop normally.

```auto
09:56:10 mine@mod-server$ node-red
6 Oct 21:56:22 - [info] 

Welcome to Node-RED
===================

6 Oct 21:56:22 - [info] Node-RED version: v3.0.2
6 Oct 21:56:22 - [info] Node.js version: v14.20.1
6 Oct 21:56:22 - [info] Linux 5.10.0-18-amd64 x64 LE
6 Oct 21:56:23 - [info] Loading palette nodes
6 Oct 21:56:25 - [info] Dashboard version 3.2.0 started at /ui
6 Oct 21:56:25 - [info] Settings file : /home/mine/.node-red/settings.js
6 Oct 21:56:25 - [info] Context store : 'memoryOnly' [module=memory]
6 Oct 21:56:25 - [info] Context store : 'file' [module=localfilesystem]
6 Oct 21:56:25 - [info] User directory : /home/mine/.node-red
6 Oct 21:56:25 - [info] Projects directory: /home/mine/.node-red/projects
6 Oct 21:56:25 - [info] Server now running at http://127.0.0.1:1880/
6 Oct 21:56:25 - [info] Active project : TEST
6 Oct 21:56:25 - [info] Flows file : /home/mine/.node-red/projects/TEST/flow.json
6 Oct 21:56:25 - [info] Starting flows
6 Oct 21:56:26 - [info] Started flows
6 Oct 21:56:26 - [info] [mqtt-broker:mqtt@localhost:1883] Connected to broker: mod_nodered@mqtt://localhost:1883

6 Oct 21:57:40 - [info] [PlaySound:bc151945aaf7784e] Event input: /home/mine/song/003.mp3
6 Oct 21:57:40 - [info] [PlaySound:bc151945aaf7784e] Play: /home/mine/song/003.mp3
6 Oct 22:05:56 - [info] [PlaySound:bc151945aaf7784e] Event exit:0, null

```

This below is the screen after I started node-red by systemd and play the file. It immediately stopped (or not even started the mplayer?)

```auto
10:16:28 mine@mod-server$ sudo systemctl start nodered.service 
[sudo] password for mine: 
10:16:42 mine@mod-server$ node-red-log 
Started Node-RED graphical event wiring tool.

6 Oct 22:16:43 - [info]
Welcome to Node-RED
===================
6 Oct 22:16:43 - [info] Node-RED version: v3.0.2
6 Oct 22:16:43 - [info] Node.js version: v14.20.1
6 Oct 22:16:43 - [info] Linux 5.10.0-18-amd64 x64 LE
6 Oct 22:16:43 - [info] Loading palette nodes
6 Oct 22:16:45 - [info] Dashboard version 3.2.0 started at /ui
6 Oct 22:16:45 - [info] Settings file : /home/mine/.node-red/settings.js
6 Oct 22:16:45 - [info] Context store : 'memoryOnly' [module=memory]
6 Oct 22:16:45 - [info] Context store : 'file' [module=localfilesystem]
6 Oct 22:16:45 - [info] User directory : /home/mine/.node-red
6 Oct 22:16:45 - [info] Projects directory: /home/mine/.node-red/projects
6 Oct 22:16:45 - [info] Server now running at http://127.0.0.1:1880/
6 Oct 22:16:45 - [info] Active project : TEST
6 Oct 22:16:45 - [info] Flows file : /home/mine/.node-red/projects/TEST/flow.json
6 Oct 22:16:45 - [info] Starting flows
6 Oct 22:16:45 - [info] Started flows
6 Oct 22:16:46 - [info] [mqtt-broker:mqtt@localhost:1883] Connected to broker: mod_nodered@mqtt://localhost:1883
6 Oct 22:17:13 - [info] [PlaySound:bc151945aaf7784e] Event input: /home/mine/song/003.mp3
6 Oct 22:17:13 - [info] [PlaySound:bc151945aaf7784e] Play: /home/mine/song/003.mp3
6 Oct 22:17:13 - [info] [PlaySound:bc151945aaf7784e] Event exit:0, null

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [7 October 2022 08:12 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/6 "2022-10-07T08:12:12Z")

</div>

Run  
`tail -f /var/log/syslog`  
and with that open try to run it again. See if anything appears in syslog.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [7 October 2022 08:23 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/7 "2022-10-07T08:23:53Z")

</div>

I think the play sound node shells out to a system command - so I suspect the environment when running as a service (from systemd) is different from running direct from command line.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [7 October 2022 08:52 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/8 "2022-10-07T08:52:26Z")

</div>

Another thing, this node hasn't been updated in over 4 years and the author hasn't been active on GitHub for over 4 years also.

At this point I would think it is safe to say the node has been abandoned.

---

<div class="post-metadata">

### Author: ![fip](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@fip](https://discourse.nodered.org/u/fip)
#### Post date: [7 October 2022 08:57 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/9 "2022-10-07T08:57:58Z")

</div>

hi @dceejay

How do I find the different environments of that specific service?

I did 3 different methods to start NR.

1. with $ node-red  

2. with $ node-red-pi  

3. with systemd: $ sudo systemctl start nodered.service  

With method #1 and #2 I can play the mp3 song with mplayer, but can not play it with method #3.

---

<div class="post-metadata">

### Author: ![fip](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@fip](https://discourse.nodered.org/u/fip)
#### Post date: [7 October 2022 08:59 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/10 "2022-10-07T08:59:37Z")

</div>

hi @zenofmud  
Yeah, I also think so.  
Do you have any other node with same functionality to suggest?

---

<div class="post-metadata">

### Author: ![fip](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@fip](https://discourse.nodered.org/u/fip)
#### Post date: [7 October 2022 09:04 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/11 "2022-10-07T09:04:42Z")

</div>

hi @Colin ,

Output from syslog did not help much. This is the screen shot of node-red started by systemd.

```auto
04:42:07 mine@mod-server$ sudo tail -f /var/log/syslog
[sudo] password for mine: 
Oct 7 04:42:11 mod-server Node-RED[2635]: 7 Oct 04:42:11 - [info] Context store : 'memoryOnly' [module=memory]
Oct 7 04:42:11 mod-server Node-RED[2635]: 7 Oct 04:42:11 - [info] Context store : 'file' [module=localfilesystem]
Oct 7 04:42:11 mod-server Node-RED[2635]: 7 Oct 04:42:11 - [info] User directory : /home/mine/.node-red
Oct 7 04:42:11 mod-server Node-RED[2635]: 7 Oct 04:42:11 - [info] Projects directory: /home/mine/.node-red/projects
Oct 7 04:42:11 mod-server Node-RED[2635]: 7 Oct 04:42:11 - [info] Server now running at http://127.0.0.1:1880/
Oct 7 04:42:11 mod-server Node-RED[2635]: 7 Oct 04:42:11 - [info] Active project : TEST
Oct 7 04:42:11 mod-server Node-RED[2635]: 7 Oct 04:42:11 - [info] Flows file : /home/pod/.node-red/projects/TEST/flow.json
Oct 7 04:42:11 mod-server Node-RED[2635]: 7 Oct 04:42:11 - [info] Starting flows
Oct 7 04:42:11 mod-server Node-RED[2635]: 7 Oct 04:42:11 - [info] Started flows
Oct 7 04:42:11 mod-server Node-RED[2635]: 7 Oct 04:42:11 - [info] [mqtt-broker:mqtt@localhost:1883] Connected to broker: mod_nodered@mqtt://localhost:1883
Oct 7 05:00:51 mod-server Node-RED[2635]: 7 Oct 05:00:51 - [info] [PlaySound:bc151945aaf7784e] Event input: /home/mine/song/003.mp3
Oct 7 05:00:51 mod-server Node-RED[2635]: 7 Oct 05:00:51 - [info] [PlaySound:bc151945aaf7784e] Play: /home/mine/song/003.mp3
Oct 7 05:00:51 mod-server Node-RED[2635]: 7 Oct 05:00:51 - [info] [PlaySound:bc151945aaf7784e] Event exit:0, null

```

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [7 October 2022 09:33 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/12 "2022-10-07T09:33:19Z")

</div>

you could take a look at `node-red-contrib-play-soundfile` and see if that would work for you.

---

<div class="post-metadata">

### Author: ![fip](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@fip](https://discourse.nodered.org/u/fip)
#### Post date: [7 October 2022 11:28 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/13 "2022-10-07T11:28:15Z")

</div>

Thanks @zenofmud.  
I will check it out.

---

<div class="post-metadata">

### Author: ![fip](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@fip](https://discourse.nodered.org/u/fip)
#### Post date: [10 October 2022 00:10 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/14 "2022-10-10T00:10:36Z")

</div>

> [@dceejay](#):
>
> I think the play sound node shells out to a system command - so I suspect the environment when running as a service (from systemd) is different from running direct from command line.

I think I should go to this direction. Thanks @dceejay.

Here is what is stated in [Using environment variables : Node-RED](https://nodered.org/docs/user-guide/environment-variables#built-in-environment-variables:)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/c/bc39384eebd31e6743e93d1727edbfd606ca50f8.png)

Does anyone have experience with this?

---

<div class="post-metadata">

### Author: ![fip](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@fip](https://discourse.nodered.org/u/fip)
#### Post date: [11 October 2022 13:54 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/15 "2022-10-11T13:54:39Z")

</div>

For those who are following this thread, I solved my original problem with adding this line in the systemd service script `/lib/systemd/system/nodered.service` :

`Environment="DISPLAY=:0"`

reloaded daemon config and restart node-red with systemd.

Anyway, this introduced another problem for me which is I can not change the audio volume anymore by changing pulseaudio volume with this error message:

`Failed to connect to pulseaudio: Connection refused`

I would appreciate if anyone here would give me pointer to any direction for solving this issue.

---

<div class="post-metadata">

### Author: ![fip](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@fip](https://discourse.nodered.org/u/fip)
#### Post date: [11 October 2022 15:25 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/16 "2022-10-11T15:25:26Z")

</div>

... and I solved the newly introduced pulseaudio volume problem by uncommenting `autospawn = yes` in this `/etc/pulse/client.conf` file and rebooting the miniPC.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [11 October 2022 18:13 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/17 "2022-10-11T18:13:57Z")

</div>

> [@fip](#):
>
> Does anyone have experience with this?

Yes. If you look into my alternate installer for node-red, you will find an example setup where the systemd script example file includes an environment file which is a lot easier to manage in case you need to make future changes. The example settings.js also makes better use of optional environment variables as well.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [11 October 2022 18:46 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/18 "2022-10-11T18:46:49Z")

</div>

No idea if this will be helpful but I wanted to satisfy my own curiosity.

Install Pico TTS using `sudo apt install libttspico-utils` then the following tiny flow will speak to you through your server's speakers assuming that at least ALSA is configured.

```auto
[{"id":"c360ce2a0183b10e","type":"inject","z":"4a3fcf357a20bf56","name":"Dave","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Look Dave, I can see you're really upset about this.","payloadType":"str","x":210,"y":1280,"wires":[["6f48f521352afcc4"]]},{"id":"6f48f521352afcc4","type":"exec","z":"4a3fcf357a20bf56","command":"pico2wave -l en-GB -w lookdave.wav \"","addpay":"payload","append":"\" && aplay lookdave.wav && rm lookdave.wav","useSpawn":"false","timer":"","winHide":true,"oldrc":false,"name":"","x":450,"y":1280,"wires":[[],[],[]]}]

```

Similarly, as long as you have ALSA installed and configured, you should be able to play various sound file formats with aplayer:

```auto
[{"id":"347583e6184bc379","type":"inject","z":"4a3fcf357a20bf56","name":"Left","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"/usr/share/sounds/alsa/Side_Left.wav","payloadType":"str","x":210,"y":1360,"wires":[["80ecb8a8c9bcb479"]]},{"id":"80ecb8a8c9bcb479","type":"exec","z":"4a3fcf357a20bf56","command":"aplay","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":true,"oldrc":false,"name":"","x":350,"y":1360,"wires":[[],[],[]]}]

```

Got some ideas on using this with a PIR detector in my office so that the server tells me if something is wrong when I walk in. Might get it to tell me the weather in the morning as well 🕶

---

<div class="post-metadata">

### Author: ![fip](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@fip](https://discourse.nodered.org/u/fip)
#### Post date: [12 October 2022 00:30 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/19 "2022-10-12T00:30:03Z")

</div>

> [@TotallyInformation](#):
>
> Yes. If you look into my alternate installer for node-red, you will find an example setup where the systemd script example file includes an environment file which is a lot easier to manage in case you need to make future changes. The example settings.js also makes better use of optional environment variables as well.

I did notice this alternative installer, but I have not tried that yet. Thank you.

---

<div class="post-metadata">

### Author: ![fip](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@fip](https://discourse.nodered.org/u/fip)
#### Post date: [12 October 2022 00:32 UTC](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624/20 "2022-10-12T00:32:21Z")

</div>

> [@TotallyInformation](#):
>
> Install Pico TTS using `sudo apt install libttspico-utils` then the following tiny flow will speak to you through your server's speakers assuming that at least ALSA is configured.

As far as I know, I did not install ALSA by intention, I only installed PulseAudio.  
I will check this suggestion later. Thanks anyway.

[Next page](https://discourse.nodered.org/t/node-red-contrib-play-sound-fails-in-node-red-on-minipc-started-from-systemd-service/68624.md?page=2)
