Playing mp3 Audio

#1

Hi, I am new to Node Red and am trying to get it play an mp3 file. I have installed three modules but can't get any of them to work. Any help would be appreciated.
These are the three modules that I tried to use:
node-red-contrib-play-sound
node-red-contrib-play-audio
node-red-contrib-play-audio-file
Thanks,
M.

0 Likes

#2

So where are you running Node-RED? Operating System, version of Node-RED version of Nodejs

Where do you want the sound to play? On the machine running Node-RED or on the machine displaying the browser?

Have you looked at the the logs to see if there are any error messages?

0 Likes

#3

Thanks for your quick reply!
Running on Windows 10
Node-RED version: v0.19.5.
Node.js version: v10.15.1

At the moment I am trying to play it in the browser of the machine that is running node red. Later I would like to play it on a Bluetooth speaker. In the console I am getting the following errors:

TypeError: Cannot read property 'pid' of undefined
at PlaySound_Node.node.play (C:\Users\mecky.node-red\node_modules\node-red-contrib-play-sound\node-red-contrib-play-sound.js:59:27)
at C:\Users\mecky.node-red\node_modules\node-red-contrib-play-sound\node-red-contrib-play-sound.js:112:10
at Layer.handle [as handle_request] (C:\Users\mecky\AppData\Roaming\npm\node_modules\node-red\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\mecky\AppData\Roaming\npm\node_modules\node-red\node_modules\express\lib\router\route.js:137:13)
at C:\Users\mecky\AppData\Roaming\npm\node_modules\node-red\red\api\auth\index.js:63:13
at Layer.handle [as handle_request] (C:\Users\mecky\AppData\Roaming\npm\node_modules\node-red\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\mecky\AppData\Roaming\npm\node_modules\node-red\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\mecky\AppData\Roaming\npm\node_modules\node-red\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\mecky\AppData\Roaming\npm\node_modules\node-red\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\mecky\AppData\Roaming\npm\node_modules\node-red\node_modules\express\lib\router\index.js:281:22

0 Likes

#4

So I'm pretty sure that node-red-contrib-play-sound works on the server that Node-RED is running on NOT from the browser.

If you want it to work in the browser you will need to use node-red-contrib-play-audio

0 Likes

#5

Note : recently many browsers stopped/blocked auto play of audio files (to be less annoyiing advert wise) - and this may stop the browser side nodes from working.

0 Likes

#6

I am fine if it plays on the sever or the browser but cannot get any of them to work.

0 Likes

#7

Great! Now you choose one and hopefully the community can help work out why its not working.

0 Likes

#8

Hey Mecky,

For playing sound in the browser, I currently use the following two nodes in my flow:

image

The dashboard's audio-out node plays sound in my dashboard, and the node-red-contrib-play-audio node plays sound in my flow editor. So both nodes play sound in the browser, but for two different applications ...

0 Likes

#9

Hi Bart,

can you play a mp3 file with those? If so, could you send me an example of how to set them up?

Thanks,
Mecky

0 Likes

#10

Hmmm, I think it is WAV. Will try this evening MP 3. Now I'm off to my great place to work :lying_face:

0 Likes

#11

Hey Mecky,

Have tested it with following flow, which downloads an mp3 from the web and plays it in the browser:

image

[{"id":"2a8146bc.01fa8a","type":"http request","z":"47b91ceb.38a754","name":"Download m3","method":"GET","ret":"bin","url":"https://www.thesoundarchive.com/email/mp_grail.mp3","tls":"","x":1260,"y":160,"wires":[["b4e7058c.12e0d8"]]},{"id":"7e9367c2.5c3018","type":"inject","z":"47b91ceb.38a754","name":"Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1070,"y":160,"wires":[["2a8146bc.01fa8a"]]},{"id":"b4e7058c.12e0d8","type":"ui_audio","z":"47b91ceb.38a754","name":"","group":"16a1f12d.07c69f","voice":"0","always":true,"x":1460,"y":160,"wires":[]},{"id":"ca47e138.e7016","type":"comment","z":"47b91ceb.38a754","name":"Play mp3 in dashboard","info":"","x":1100,"y":120,"wires":[]},{"id":"fb9523fe.0686d","type":"http request","z":"47b91ceb.38a754","name":"Download m3","method":"GET","ret":"bin","url":"https://www.thesoundarchive.com/email/mp_grail.mp3","tls":"","x":1260,"y":260,"wires":[["4b104bb8.b27cd4"]]},{"id":"9fa09162.6a45b","type":"inject","z":"47b91ceb.38a754","name":"Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1070,"y":260,"wires":[["fb9523fe.0686d"]]},{"id":"f9554a1d.16f3d8","type":"comment","z":"47b91ceb.38a754","name":"Play mp3 in flow editor","info":"","x":1100,"y":220,"wires":[]},{"id":"4b104bb8.b27cd4","type":"play audio","z":"47b91ceb.38a754","name":"","voice":"","x":1470,"y":260,"wires":[]},{"id":"16a1f12d.07c69f","type":"ui_group","z":"","name":"Default","tab":"f136a522.adc2a8","order":1,"disp":true,"width":"6"},{"id":"f136a522.adc2a8","type":"ui_tab","z":"","name":"Home","icon":"home","order":1}]

I run Node-RED on a Raspberry PI 3 model B and did the tests in browsers on Windows 10. It works fine in Chrome/Firefox/Edge both for flow editor and dashboard. So 6 tests in total ...

A couple of remarks:

  • The output of my http-request node is binary buffer. Don't convert audio or video anywhere to strings ...
  • In the audio-out node I have selected the checkbox 'Play audio when window not in focus, because it won't play otherwise when the tab (where you have added your audio-out node) isn't visible at the moment ...
0 Likes

#12

Thanks Bart! Is it possible to grab the mp3 from the local computer too? Instead of a http request, what would I have to use?

0 Likes

#13

I used the http-request node to make sure you have 'exact the same' data as in my tests. If that works in your case (???), then you know at least that the browser isn't your problem...

I think you just need to use the file-in node. But make sure you specify binary output (instead of string or text or whatever)!!!!

0 Likes

#14

@meckyreuss - if by 'local computer' you mean the computer running the browser, the file-in node reads the file only from the machine NR is running on.

If the browser is running on the machine NR is running on, it will work, but it the browser is runnig on 'A' and NR is running on 'B' the file-in node can only read files from 'B'

0 Likes

#15

Works like a charm!!! Is there a possibility to

  1. add a stop, pause and rewind into the flow?
  2. add a timer that triggers events at predefined times?

Thanks!
Mecky

0 Likes

#16
  • We added a stop functionality some time ago via this pull-request (via msg.reset).
  • The rewind is certainly not implemented.
  • When you look at the discussion (related to that pull request), we didn't add pause functionality in that pull-request. Reason is that web audio doesn't support pause/resume out-of-the-box. There are workarounds to get it done, but I don't have the time at the moment to implement that...

Yes you can use the Interval-node, Inject-node, BigTimer-node ... There are plenty examples available when you search in Google or in this forum.

0 Likes