Playing a .mp3 flie

I've read a few posts about playing MP3 files and that browsers are blocking sounds.

Taking that on, I decided to try another way but still to no avail.

Ubuntu.
NR 0.20.5

Putting aside the nodes to play sounds, I decided to do it old school and opened a shell and entered the command:
play (path to MP3 file)
and it plays/I hear the sound.

So, if I put it in a flow:

[{"id":"badf7b6a.fcb05","type":"exec","z":"9245b569.9f881","command":"play /home/me/Music/DontTouchTheButton.mp3","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":660,"y":2310,"wires":[[],[],[]]},{"id":"95671573.d5767","type":"inject","z":"9245b569.9f881","name":"","topic":"","payload":"/home/me/Music/DontTouchTheButton.mp3","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":2310,"wires":[["badf7b6a.fcb05"]]}]

Press the button and nothing is heard.

Why?

This way would/should get around the browser blocking sounds being played, and if I do it from a terminal, it works.

I would start by using the full path of the play command.
On commandline enter which play and use that path in the exec node.

Then comes the question, does node-red have permission to execute play and does it have permission to use the audio device.

Thanks.

which play
yields
/usr/bin/play

So I modified the command.

Still nothing.

How do I find out if NR has permission, etc?

Just checking that you realise that would play it on the device running node-red, not on the machine running the browser, if they are different.

1 Like

They are one in the same.

Sorry. Mind is all over the place.

For the sake of getting something working I am just wanting to get NR to play a sound file on this machine when I press a button on NR on this machine.

When I get that working, I can expand what is happening.
Any remote triggering would all be on this machine. So I think I have got around the problem of "which machine" is being used.

Do you get an error from the exec node (check all the outputs of the node to see what it says).

Stupid me forgot to add debug nodes on the output of the exe node.

Did it.

All looks good, but this is what I see:

/home/me/Music/DontTouchTheButton.mp3: File Size: 36.2k     Bit Rate: 173k  Encoding: MPEG audio      Channels: 2 @ 16-bit   Samplerate: 44100Hz      Replaygain: off           Duration: 00:00:01.67  In:0.00% 00:00:00.00 [00:00:01.67] Out:0     [      |      ]        Clip:0    In:11.1% 00:00:00.19 [00:00:01.49] Out:8.19k [  ====|====  ]        Clip:0    In:22.2% 00:00:00.37 [00:00:01.30] Out:16.4k [  ====|====  ]        Clip:0    In:27.8% 00:00:00.46 [00:00:01.21] Out:20.5k [   -==|===   ]        Clip:0    In:38.9% 00:00:00.65 [00:00:01.02] Out:28.7k [  ====|====  ]        Clip:0    In:44.5% 00:00:00.74 [00:00:00.93] Out:32.8k [  ====|====  ]        Clip:0    In:55.6% 00:00:00.93 [00:00:00.74] Out:41.0k [  ====|====  ]        Clip:0    In:61.1% 00:00:01.02 [00:00:00.65] Out:45.1k [   -==|==    ]        Clip:0    In:72.3% 00:00:01.21 [00:00:00.46] Out:53.2k [  ====|====  ]        Clip:0    In:77.8% 00:00:01.30 [00:00:00.37] Out:57.3k [  ====|====  ]        Clip:0    ...

(oh, that is from the error output. But it doesn't say what the error is.

Fair enough.

But no sound.

From the CLI I get:

me@me-desktop:~/Music$ play DontTouchTheButton.mp3 

DontTouchTheButton.mp3:

 File Size: 36.2k     Bit Rate: 173k
  Encoding: MPEG audio    
  Channels: 2 @ 16-bit   
Samplerate: 44100Hz      
Replaygain: off         
  Duration: 00:00:01.67  

In:100%  00:00:01.67 [00:00:00.00] Out:73.7k [      |      ]        Clip:0    
Done.
me@me-desktop:~/Music$ 

And I hear the sound.

I suspect you need to specify the audio out device and/or node-red does not have access to it.
should be in /dev/audio or /dev/dsp or something similar. Look for the permissions on the relevant file.

Sorry @bakman2, I am not understanding.

The file (sample) is in /home/me/Music/......

play in in usr/bin/play

Sorry, but which relevant file?

Seems I have a big dose of blonde lately.

back to basics. I see from your first post NR v0.20.5 but

  1. what version of node.js
  2. what type of machine?
  3. what OS is it running
  4. what does
    ls -al usr/bin/play
    show?
  5. what does
    ls -al /home/me/Music/DontTouchTheButton.mp3
    show
me@me-desktop:~/Music$ node -v
v8.16.2
me@me-desktop:~/Music$ 

NUC I7

Ubuntu 18.04 LTS

(I think this is where the problem is)

me@me-desktop:~/Music$ ls -al /usr/bin/play
lrwxrwxrwx 1 root root 3 Aug  2 01:27 /usr/bin/play -> sox
me@me-desktop:~/Music$ 

(you missed the leading / from the path. No problems)

me@me-desktop:~/Music$ ls -al /home/me/Music/DontTouchTheButton.mp3
-rw-rw-r-- 1 me me 36211 Nov 16 18:02 /home/me/Music/DontTouchTheButton.mp3
me@me-desktop:~/Music$ 

I tried it with sox in the CLI and it is worse. It is expecting other inputs.

(For help/clarity)

This is what happens:

me@me-desktop:~/Music$ ls -al /usr/bin/play
lrwxrwxrwx 1 root root 3 Aug  2 01:27 /usr/bin/play -> sox
me@me-desktop:~/Music$ play DontTouchTheButton.mp3 

DontTouchTheButton.mp3:

 File Size: 36.2k     Bit Rate: 173k
  Encoding: MPEG audio    
  Channels: 2 @ 16-bit   
Samplerate: 44100Hz      
Replaygain: off         
  Duration: 00:00:01.67  

In:100%  00:00:01.67 [00:00:00.00] Out:73.7k [      |      ]        Clip:0    
Done.
me@me-desktop:~/Music$ sox DontTouchTheButton.mp3 
sox:      SoX v14.4.2

sox FAIL sox: Not enough input filenames specified

Usage summary: [gopts] [[fopts] infile]... [fopts] outfile [effect [effopt]]...

SPECIAL FILENAMES (infile, outfile):
-                        Pipe/redirect input/output (stdin/stdout); may need -t
-d, --default-device     Use the default audio device (where available)
-n, --null               Use the `null' file handler; e.g. with synth effect
-p, --sox-pipe           Alias for `-t sox -'

SPECIAL FILENAMES (infile only):
"|program [options] ..." Pipe input from external program (where supported)
http://server/file       Use the given URL as input file (where supported)

GLOBAL OPTIONS (gopts) (can be specified at any point before the first effect):
--buffer BYTES           Set the size of all processing buffers (default 8192)
--clobber                Don't prompt to overwrite output file (default)
--combine concatenate    Concatenate all input files (default for sox, rec)
--combine sequence       Sequence all input files (default for play)
-D, --no-dither          Don't dither automatically
--dft-min NUM            Minimum size (log2) for DFT processing (default 10)
--effects-file FILENAME  File containing effects and options
-G, --guard              Use temporary files to guard against clipping
-h, --help               Display version number and usage information
--help-effect NAME       Show usage of effect NAME, or NAME=all for all
--help-format NAME       Show info on format NAME, or NAME=all for all
--i, --info              Behave as soxi(1)
--input-buffer BYTES     Override the input buffer size (default: as --buffer)
--no-clobber             Prompt to overwrite output file
-m, --combine mix        Mix multiple input files (instead of concatenating)
--combine mix-power      Mix to equal power (instead of concatenating)
-M, --combine merge      Merge multiple input files (instead of concatenating)
--magic                  Use `magic' file-type detection
--multi-threaded         Enable parallel effects channels processing
--norm                   Guard (see --guard) & normalise
--play-rate-arg ARG      Default `rate' argument for auto-resample with `play'
--plot gnuplot|octave    Generate script to plot response of filter effect
-q, --no-show-progress   Run in quiet mode; opposite of -S
--replay-gain track|album|off  Default: off (sox, rec), track (play)
-R                       Use default random numbers (same on each run of SoX)
-S, --show-progress      Display progress while processing audio data
--single-threaded        Disable parallel effects channels processing
--temp DIRECTORY         Specify the directory to use for temporary files
-T, --combine multiply   Multiply samples of corresponding channels from all
                         input files (instead of concatenating)
--version                Display version number of SoX and exit
-V[LEVEL]                Increment or set verbosity level (default 2); levels:
                           1: failure messages
                           2: warnings
                           3: details of processing
                           4-6: increasing levels of debug messages
FORMAT OPTIONS (fopts):
Input file format options need only be supplied for files that are headerless.
Output files will have the same format as the input file where possible and not
overridden by any of various means including providing output format options.

-v|--volume FACTOR       Input file volume adjustment factor (real number)
--ignore-length          Ignore input file length given in header; read to EOF
-t|--type FILETYPE       File type of audio
-e|--encoding ENCODING   Set encoding (ENCODING may be one of signed-integer,
                         unsigned-integer, floating-point, mu-law, a-law,
                         ima-adpcm, ms-adpcm, gsm-full-rate)
-b|--bits BITS           Encoded sample size in bits
-N|--reverse-nibbles     Encoded nibble-order
-X|--reverse-bits        Encoded bit-order
--endian little|big|swap Encoded byte-order; swap means opposite to default
-L/-B/-x                 Short options for the above
-c|--channels CHANNELS   Number of channels of audio data; e.g. 2 = stereo
-r|--rate RATE           Sample rate of audio
-C|--compression FACTOR  Compression factor for output format
--add-comment TEXT       Append output file comment
--comment TEXT           Specify comment text for the output file
--comment-file FILENAME  File containing comment text for the output file
--no-glob                Don't `glob' wildcard match the following filename

AUDIO FILE FORMATS: 8svx aif aifc aiff aiffc al amb amr-nb amr-wb anb au avr awb caf cdda cdr cvs cvsd cvu dat dvms f32 f4 f64 f8 fap flac fssd gsm gsrt hcom htk ima ircam la lpc lpc10 lu mat mat4 mat5 maud mp2 mp3 nist ogg paf prc pvf raw s1 s16 s2 s24 s3 s32 s4 s8 sb sd2 sds sf sl sln smp snd sndfile sndr sndt sou sox sph sw txw u1 u16 u2 u24 u3 u32 u4 u8 ub ul uw vms voc vorbis vox w64 wav wavpcm wv wve xa xi
PLAYLIST FORMATS: m3u pls
AUDIO DEVICE DRIVERS: alsa ao oss ossdsp pulseaudio

EFFECTS: allpass band bandpass bandreject bass bend biquad chorus channels compand contrast dcshift deemph delay dither divide+ downsample earwax echo echos equalizer fade fir firfit+ flanger gain highpass hilbert input# ladspa loudness lowpass mcompand noiseprof noisered norm oops output# overdrive pad phaser pitch rate remix repeat reverb reverse riaa silence sinc spectrogram speed splice stat stats stretch swap synth tempo treble tremolo trim upsample vad vol
  * Deprecated effect    + Experimental effect    # LibSoX-only effect
EFFECT OPTIONS (effopts): effect dependent; see --help-effect
me@me-desktop:~/Music$ 

As said: in /dev

cd /dev
ls -l 

Look for a file audio, alsa, dsp - something that could resemble an audio driver.
Then look for the permissions on those files.

If they are crw------- 1 root root - node-red cannot access them and you will need to modify the permissions.

Just for your info, I have been using node-red-contrib-play-sound quite successfully on a rpi for quite some time. I'll post the flow in Share Your Projects in a little bit.

@bakman2,

I missed that and can't find it in this thread.

Ok, sorry did find it.

I suspect you need to specify the audio out device and/or node-red does not have access to it.
should be in /dev/audio or /dev/dsp or something similar. Look for the permissions on the
relevant file

But doing that I get this and there is no audio, alas or dsp.

However, I'm not sure I get it. If run from the CLI it works, so the required thing/s are in there somewhere.

me@me-desktop:~$ cd /dev
me@me-desktop:/dev$ ls -l
total 0
crw-r--r--  1 root root       10,   235 Nov 17 08:45 autofs
drwxr-xr-x  2 root root             820 Nov 17 08:45 block
drwxr-xr-x  2 root root              80 Nov 17 08:45 bsg
crw-------  1 root root       10,   234 Nov 17 08:45 btrfs-control
drwxr-xr-x  3 root root              60 Nov 17 08:44 bus
lrwxrwxrwx  1 root root               3 Nov 17 08:45 cdrom -> sr0
lrwxrwxrwx  1 root root               3 Nov 17 08:45 cdrw -> sr0
drwxr-xr-x  2 root root            4300 Nov 17 08:46 char
crw-------  1 root root        5,     1 Nov 17 08:45 console
lrwxrwxrwx  1 root root              11 Nov 17 08:44 core -> /proc/kcore
drwxr-xr-x  2 root root              60 Nov 17 08:44 cpu
crw-------  1 root root       10,    59 Nov 17 08:45 cpu_dma_latency
crw-------  1 root root       10,   203 Nov 17 08:45 cuse
drwxr-xr-x  6 root root             120 Nov 17 08:45 disk
drwxr-xr-x  3 root root             100 Nov 17 08:45 dri
crw-------  1 root root      239,     0 Nov 17 08:45 drm_dp_aux0
crw-------  1 root root      239,     1 Nov 17 08:45 drm_dp_aux1
lrwxrwxrwx  1 root root               3 Nov 17 08:45 dvd -> sr0
crw-------  1 root root       10,    61 Nov 17 08:45 ecryptfs
crw-rw----  1 root video      29,     0 Nov 17 08:45 fb0

Thanks.

I'll download it and see what happens.

Yikes! That is a lot of work.

I guess that a bit of congrats on the effort put in to the flow.

For the sake of testing, I ported it to my RPI for music playing.

Edited the path and tried it.

SILENCE.

Looking into that it is probably because of this:

numid=1,iface=MIXER,name='PCM Playback Volume'  ; type=INTEGER,access=rw---R--,values=1,min=-10239,max=400,step=0  : values=125  | dBscale-min=-102.39dB,step=0.01dB,mute=1

I use HDMI output.

I see the name of what is playing. Though all I see is the directory name/artist rather than the actual song.

The buttons maybe do something but as there is no audio I can't say. But the name changes if I press the next/previous enough times.

(though that is a whole other issue in a lot of ways.)

I don't know if the flow needs a specific player installed to work.
I know I had to install the play sound node.

Bug report on the flow:

On the first page of the flow there are two nodes in which you must enter the path to the music.

That caught me out as I only edited one and that may be why the music isn't playing.
And the node with this in needs to be changed to what I have:
amixer cset numid=3 2

As it says in the description, I use the HiFiBerry MiniAmp to output the sound. If you are using another rocess to play the sound, you are going to have to make some changes.

Yeah, ok sorry about that.

It looks great and I do accept the work you put in to it.

It also doesn't seem to like MP3 files.

After editing the paths (plural) to where I have the MP3 files on the RPI, it see this in the debug window from a node:

{"_msgid":"ae32970c.01f888","topic":"","fileURL":"/home/pi/Music/MP3","song_count":57}

Just a few more than 57.
On reflection that may be how many directories are in that folder. Dunno. But 57 is a rough approximation of the directories.

But is that because it is looking for .WAV files and not MP3?

Again, I do appreciate the flow and how it looks.

Alas it has taken me on a weird journey from why I can't play MP3 files on a NUC running NR to playing .WAV files on a RPI.

It isn't really helping me work out what is going on.

If anyone is still reading this:

I am not further down the track of understanding why:
play /home/me/Music/DontTouchTheButton.mp3
from a terminal/CLI works. All things on THIS machine.

If I put that into a NR exec node it doesn't.

Yet, with debug nodes on all three outputs of the node, it would seem it works/ed.

Output #1: ""
Output #2: /home/me/Music/DontTouchTheButton.mp3: File Size: 36.2k Bit Rate: 173k Encoding: MPEG audio Channels: 2 @ 16-bit Samplerate: 44100Hz Replaygain: off Duration: 00:00:01.67 In:0.00% 00:00:00.00 [00:00:01.67] Out:0 [ | ] Clip:0 In:11.1% 00:00:00.19 [00:00:01.49] Out:8.19k [ ====|==== ] Clip:0 In:22.2% 00:00:00.37 [00:00:01.30] Out:16.4k [ ====|==== ] Clip:0 In:27.8% 00:00:00.46 [00:00:01.21] Out:20.5k [ -==|=== ] Clip:0 In:38.9% 00:00:00.65 [00:00:01.02] Out:28.7k [ ====|==== ] Clip:0 In:44.5% 00:00:00.74 [00:00:00.93] Out:32.8k [ ====|==== ] Clip:0 In:55.6% 00:00:00.93 [00:00:00.74] Out:41.0k [ ====|==== ] Clip:0 In:61.1% 00:00:01.02 [00:00:00.65] Out:45.1k [ -==|== ] Clip:0 In:72.3% 00:00:01.21 [00:00:00.46] Out:53.2k [ ====|==== ] Clip:0 In:77.8% 00:00:01.30 [00:00:00.37] Out:57.3k [ ====|==== ] Clip:0 ...
Output #3: {"code":0}

So, where now?

Oh, I have also looked at this:
Someone with similar problems

That flow works. I hear the sound.

Further complicating the issue - for me at least.