# How to play a sound?

**URL:** <https://discourse.nodered.org/t/how-to-play-a-sound/14509>\
**Category:** General\
**Created:** [19 August 2019 23:28 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509 "2019-08-19T23:28:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [19 August 2019 23:28 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/1 "2019-08-19T23:28:26Z")

</div>

I am wanting to play a sound (MP3) on a ubuntu machine.

I have got 3 nodes but can't get any of them to work.

Say the file is called "sound.mp3". It can be where ever you want.

How would I got it to play when I send a signal to the node?

Basically this:

![Screenshot%20from%202019-08-20%2009-27-28](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2dc3c54fe2c1bf0ef433336cafed7879b9e89527.png)

I know that's a function node. But just to show the idea of what I am saying.

I went a bit rogue and tried this too:

```auto
[{"id":"54c7109a.bf10d8","type":"inject","z":"9c1e5490.5d70b","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":580,"wires":[["de798816.862268"]]},{"id":"ffe9a2de.ed2d5","type":"debug","z":"9c1e5490.5d70b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":560,"wires":[]},{"id":"de798816.862268","type":"exec","z":"9c1e5490.5d70b","command":"mpg123 /home/me/.node-red/public/Sounds/Bell-ding-loud.mp3","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Ding","x":300,"y":580,"wires":[[],["ffe9a2de.ed2d5"],["d782c383.3f657"]]},{"id":"d782c383.3f657","type":"debug","z":"9c1e5490.5d70b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":600,"wires":[]}]

```

SILENCE.

But the outputs are:

```auto
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3	version 1.25.10; written and copyright by Michael Hipp and others	free software (LGPL) without any warranty but with best wishesDirectory: /home/me/.node-red/public/Sounds/Playing MPEG stream 1 of 1: Bell-ding-loud.mp3 ...MPEG 1.0 L III cbr192 44100 j-s[0:06] Decoding of Bell-ding-loud.mp3 finished.

```

And `{"code":0}` for the second debug node.

If I do it from the CLI it plays.

Where's the elephant?

---

<div class="post-metadata">

**Author:** ![wb666greene](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wb666greene/32/6534_2.png) [@wb666greene](https://discourse.nodered.org/u/wb666greene)\
**Post date:** [20 August 2019 03:53 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/2 "2019-08-20T03:53:04Z")

</div>

Looking at your exec sample flow I believe you need the full path to the mpg123 command, something like /usr/bin/mpg123 depending where your system puts it. Also you might try exec mode instead of spawn mode, although I don't think it should really matter in this case.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 August 2019 04:20 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/3 "2019-08-20T04:20:54Z")

</div>

Appreciated.

I would think that mpg123 is being called. It is shown in the output from the exec node.  
That is pretty well what I see when I type it in the CLI.

So I don't think the path needs to be specified. If it wasn't finding the command, I wouldn't be seeing the  
`High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3 version 1.25.10; written and copyright by Michael Hipp and others` etc

---

<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:** [20 August 2019 05:37 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/4 "2019-08-20T05:37:03Z")

</div>

Where is the flow running ? Where are the speakers plugged in ? Rc of 0 looks like it should have worked.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 August 2019 07:00 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/5 "2019-08-20T07:00:45Z")

</div>

It is running on THIS machine. Speakers - via HDMI.

mpg123 is installed.

If I use mpg123 to play the sound from the cli, it works.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [20 August 2019 08:42 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/6 "2019-08-20T08:42:57Z")

</div>

_Edited title, unless someone is searching for "dumb" it is not very useful.  
Can we use descriptive titles ?_

---

<div class="post-metadata">

**Author:** ![wb666greene](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wb666greene/32/6534_2.png) [@wb666greene](https://discourse.nodered.org/u/wb666greene)\
**Post date:** [20 August 2019 12:33 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/7 "2019-08-20T12:33:35Z")

</div>

On my Ubuntu desktop I had to use:

mpg123 -a /dev/audio /absolute/path/sound.mp3

In order to get your sample flow to play.

Might help to change your Pi from auto (the normal default) to HDMI in raspi-config.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 August 2019 12:40 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/8 "2019-08-20T12:40:52Z")

</div>

This isn't a RPI at this stage.

I'm on a UBUNTU NUC at this stage.

It may go to a RPI but for now, it can't/won't.

Thanks. Shall try and get back to you.

Well.... Alas other than a lot more happening in the debug window (right of the screen) nothing much happened.

Doing what you say form a TERMINAL (CLI) it really goes mental.  
Lots of output with errors but the sound plays.

But just the vanilla:  
`mpg123 /path/to/sound/file.mp3` works.

Appreciated though.

I'm not sure there is a better node to play an MP3 file to the computer's speakers.

---

<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:** [20 August 2019 13:31 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/9 "2019-08-20T13:31:04Z")

</div>

What errors when you run in terminal?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 August 2019 13:34 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/10 "2019-08-20T13:34:18Z")

</div>

None from terminal.

```auto
me@me-desktop:~$ mpg123 /home/me/.node-red/public/Sounds/Bell-ding-loud.mp3 
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
	version 1.25.10; written and copyright by Michael Hipp and others
	free software (LGPL) without any warranty but with best wishes

Directory: /home/me/.node-red/public/Sounds/

Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: Bell-ding-loud.mp3 ...

MPEG 1.0 L III cbr192 44100 j-s

[0:06] Decoding of Bell-ding-loud.mp3 finished.
me@me-desktop:~$ 

```

Adding what was suggested I get this:

```auto
me@me-desktop:~$ mpg123 -a /dev/audio /home/me/.node-red/public/Sounds/Bell-ding-loud.mp3 
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
	version 1.25.10; written and copyright by Michael Hipp and others
	free software (LGPL) without any warranty but with best wishes
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

Directory: /home/me/.node-red/public/Sounds/

Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: Bell-ding-loud.mp3 ...

MPEG 1.0 L III cbr192 44100 j-s
ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred

[0:06] Decoding of Bell-ding-loud.mp3 finished.
me@me-desktop:~$ 

```

Both cases the sound plays.

---

<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:** [20 August 2019 13:45 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/11 "2019-08-20T13:45:13Z")

</div>

So /dev/audio doesn't exist on your system. Try /dev/dsp

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 August 2019 13:49 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/12 "2019-08-20T13:49:08Z")

</div>

Yeah, ok, but if I just do the command:  
`mpg123 (sound file)` it works.  
I showed that.

Can you explain why the `/dev/dsp` is needed?

---

<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:** [20 August 2019 14:34 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/13 "2019-08-20T14:34:51Z")

</div>

Not really, for some reason when you run it from the exec node it does not have a default device enabled (or it points to the wrong device), so you have to specify it explicitly.  
What does  
`ls -l /dev/dsp*` show?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 August 2019 21:01 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/14 "2019-08-20T21:01:07Z")

</div>

```auto
me@me-desktop:~$ ls -l /dev/dsp*
ls: cannot access '/dev/dsp*': No such file or directory
me@me-desktop:~$ 

```

---

<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:** [21 August 2019 07:14 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/15 "2019-08-21T07:14:28Z")

</div>

> [@Trying\_to\_learn](#):
>
> cannot access '/dev/dsp\*': No such file or directory

Well that is just ridiculous. I can't explain that at all.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [21 August 2019 09:09 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/16 "2019-08-21T09:09:51Z")

</div>

Could be an device located in `/dev/snd/`

Try:  
`aplay -l`

In my case that shows up as:

```auto
****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: ALC3239 Analog [ALC3239 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

```

The device is card 1, subdevice 0 in my case.

`mpg123 -a hw:1,0 <file>`

---

<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:** [21 August 2019 09:23 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/17 "2019-08-21T09:23:58Z")

</div>

But /dev/dsp works when @Trying_to_learn runs mpg123 from an exec node. In which case I don't understand why `ls /dev/dsp` doesn't find it.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 August 2019 09:54 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/18 "2019-08-21T09:54:37Z")

</div>

> [@bakman2](#):
>
> Try:  
> `aplay -l`

In reply:  
`me@me-desktop:~$ aplay -l ****List of PLAYBACK Hardware Devices**** card 0: PCH [HDA Intel PCH], device 0: ALC283 Analog [ALC283 Analog] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0] Subdevices: 0/1 Subdevice #0: subdevice #0 card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: PCH [HDA Intel PCH], device 9: HDMI 3 [HDMI 3] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: PCH [HDA Intel PCH], device 10: HDMI 4 [HDMI 4] Subdevices: 1/1 Subdevice #0: subdevice #0 me@me-desktop:~$`

Now, the /dev/snd/

`me@me-desktop:~$ ls /dev/snd by-path hwC0D0 pcmC0D0c pcmC0D10p pcmC0D7p pcmC0D9p timer controlC0 hwC0D2 pcmC0D0p pcmC0D3p pcmC0D8p seq me@me-desktop:~$`

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [21 August 2019 10:13 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/19 "2019-08-21T10:13:17Z")

</div>

Does this work in node-red ?

`mpg123 -a hw:0,0 /home/me/.node-red/public/Sounds/Bell-ding-loud.mp3`

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 August 2019 10:17 UTC](https://discourse.nodered.org/t/how-to-play-a-sound/14509/20 "2019-08-21T10:17:03Z")

</div>

☹ No.

If I do that from the CLI it also does **not** play a sound.

`mpg123 -a hw:0,0 /home/me/.node-red/public/Sounds/Bell-ding-loud.mp3`

But if I negate the `-a hw:0,0` bit, it works from the CLI.

[Next page](https://discourse.nodered.org/t/how-to-play-a-sound/14509.md?page=2)
