Exec node calling python running pulse audio getting 'connection refused

[ADMIN: moved from another thread because it is a new issue]

Okay but after running the program and executing the python script, it gives me this new error saying this:

image

What went wrong?

What node did that come from?
where are you using pulse audio?

basically the connection to pulseaudio was refused so you have to figure out why. How are you calling it?

have you done a google search about the error?
try searching using 'node-red pulseaudio'

From the Exec Node, the command inside is this: python3 /home/pi/discord-bot-one/musicPlayer.py

This is the code inside the python script:

import vlc

p = vlc.MediaPlayer('/home/pi/discord-bot-one/song44.mp3')
p.play()
print("Music is Now Playing")

So what happens if you run that command in a terminal window on the pi?

Also, did you do the google search?

Fails to play the sound, and when doing VLC "this song" then it just shows "pid random number"

So you're saying that your python program is not working? You need to get that working first.

Sorry for leaving out details as I was tired when typing that, but executing the python script, which i provided in the previous comment works perfectly on the Pi itself. I have also done the usual "vlc directory.musicname.mp3" style on the command line and that works well to, looking back it may just be a problem with VLC itself, maybe I may have to use another mp3 program?

do you have python3-vlc installed?

sudo apt install python3-vlc

interesting because for me it does not work.

pi@yellowpi:~/discord-bot-one $ python3 musicPlayer.py
[01d6a988] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
[01da1588] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
Music is Now Playing
pi@yellowpi:~/discord-bot-one $ 
pi@yellowpi:~/discord-bot-one $ cat musicPlayer.py
import vlc
media = vlc.MediaPlayer('/home/pi/discord-bot-one/song44.mp3')
media.play()
print("Music is Now Playing")
pi@yellowpi:~/discord-bot-one $ 

However I did find this tidbit: python - python3 vlc module - no audio - Stack Overflow
and changing the program to this:

import time
import vlc
media = vlc.MediaPlayer('file:///home/pi/discord-bot-one/song44.mp3')
#cvlc /home/pi/discord-bot-one/song44.mp3
media.play()
time.sleep(30)
print("Music is Now Playing")

it does play but does display

[ **01d6a988** ] vlcpulse audio output error: **PulseAudio server connection failure: Connection refused**
[ **01da1588** ] vlcpulse audio output error: **PulseAudio server connection failure: Connection refused**

Tried with your changes and it still gave me this output

[019e5be0] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
[01a16270] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
[01a16270] alsa audio output error: cannot open ALSA device "default": Device or resource busy
[01a16270] main audio output error: Audio output failed
[01a16270] main audio output error: The audio device "default" could not be used:
Device or resource busy.
[01a16270] main audio output error: module not functional
[7262bf20] main decoder error: failed to create audio output

[I've moved this to its own topic]

Lets review.
Please provide the following

  1. what model Pi are you running NR on and what software version are you using?
  2. Please stop/start Node-RED and then copy and paste the startup log
  3. How did you install ASLA?
  4. do you have python3-vlc installed?
  5. have you a speaker plugged into the Pi's earphone jack?
  6. please export and attach your current flow
  7. please provide the current version of your python program.

Once I get all this, I'll take another look.

  1. My Pi Model is Model 3B+

  1. I just checked and did a "sudo apt-get install alsa-utils", seems it was already on the system.
    image

  2. Yes

  3. Yes

[
    {
        "id": "880192a506a1f490",
        "type": "debug",
        "z": "e1a1903309a59482",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 710,
        "y": 80,
        "wires": []
    },
    {
        "id": "e603bb071891dc24",
        "type": "exec",
        "z": "e1a1903309a59482",
        "command": "python3 /home/pi/discord-bot-one/musicPlayer.py",
        "addpay": "",
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 970,
        "y": 300,
        "wires": [
            [],
            [
                "f5a24019efb82879"
            ],
            []
        ]
    },
    {
        "id": "830ee7b453faecee",
        "type": "serial in",
        "z": "e1a1903309a59482",
        "name": "Arduino Uno",
        "serial": "4f56b568bc65e2cd",
        "x": 270,
        "y": 320,
        "wires": [
            [
                "b3b5a8d37d82fc4b",
                "a327079557ed0ecf"
            ]
        ]
    },
    {
        "id": "327d4cdc2343bd8b",
        "type": "inject",
        "z": "e1a1903309a59482",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "Distance: 20cm",
        "payloadType": "str",
        "x": 680,
        "y": 180,
        "wires": [
            [
                "a327079557ed0ecf",
                "880192a506a1f490"
            ]
        ]
    },
    {
        "id": "a327079557ed0ecf",
        "type": "switch",
        "z": "e1a1903309a59482",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "cont",
                "v": "Distance: 20cm",
                "vt": "str"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 710,
        "y": 320,
        "wires": [
            [
                "e603bb071891dc24"
            ],
            []
        ]
    },
    {
        "id": "f5a24019efb82879",
        "type": "debug",
        "z": "e1a1903309a59482",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1150,
        "y": 360,
        "wires": []
    },
    {
        "id": "b3b5a8d37d82fc4b",
        "type": "debug",
        "z": "e1a1903309a59482",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 520,
        "y": 400,
        "wires": []
    },
    {
        "id": "4f56b568bc65e2cd",
        "type": "serial-port",
        "serialport": "/dev/ttyACM0",
        "serialbaud": "9600",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "waitfor": "",
        "dtr": "none",
        "rts": "none",
        "cts": "none",
        "dsr": "none",
        "newline": "\\n",
        "bin": "false",
        "out": "char",
        "addchar": "",
        "responsetimeout": "10000"
    }
]
  1. Python 3.7.3

The weirdest part is that literally any other command works, just not the audio/vlc command for some reason. Like I can remotely shut it down and etc just by using the exec node or even make a random directory, but cannot play sound? Is it to do with the account permissions or something?

I should have been clearer, I want the current code on the python program.

I'm currently updating a PI 3B to NR v2.0.6 and node.js 14.17.6 so I'll be a little ahead of you. I have the same version of also-utils installed.

It could let me see if the change of NR version has an effect (I was on 1.3.5)

Sorry it took so long to get back to you but yard work called :slightly_smiling_face:

Yeah no problem man, I really appreciate the help nevertheless.

import vlc
import time

p = vlc.MediaPlayer('file:///home/pi/discord-bot-one/song44.mp3')
p.play()
time.sleep(30)
print("Music is Now Playing")

Running this code just on the Pi by doing the python3 musicPlayer.py command works just fine, it also works fine when I go on its IDE and run it from there.

What happens if you put an inject node connected to the exec node, deploy and press the inject anything?

and from the CLI on the PI what do you get if you run this command: groups pi

The inject node is used as a test trigger to satisfy the conditions I made on the switch: it's basically a button to play the music along with the Arduino.

Output from CLI when running the given command:

What os and version are you using? run this cat /etc/os-release

Oh, are you running the audio to HDMI?
if so try this sudo amixer cset numid=3 1
(gotten from vlc trouble - Raspberry Pi Forums)

In terms of where i'm running audio, i changed the route into my bluetooth earphones if that' alright. It works fine when playing music on the Pi.

OS Version below:
image

I would try routing it back to just the audio plug and see what happens

[edited] have you thought about using one of the sound nodes like

Took your advice and discovered something interesting from it; it speaks what I printed from my python code, yet refuses to play the music. So the code runs alright but PulseAudio seems to c***block it for no reason at all giving the same "connection refused" output. Even with the routing it still does nothing. Are there permissions for it that we're missing?

I do also run Node Red from the root so maybe there's something wrong somewhere with the audio software?