Exec command does not work like the same command in the cli

Ok, I've wasted too much time on this "espeak" exec node... has anyone seen this before?

This command works fine using my login from the command line on my rpi4 running ubuntu 10.20:

srickus@shrpi4:~$ espeak -ven+f4 -k5 -s150 "testing 123"

In my experience this means that the environment is different between you logged into your account and what NR is running in. Check user and group that NR is in and also dump the environment, like 'set; espeak -ven+f4 -k5 -s150 "testing 123"' and compare it to "set" run from your terminal. I'm not sure I have the quotes correct but I think you can work that out.

Well, I thought you were onto something there -- it seems that my user needs to have access to the audio group. However, adding my login to that group and restarting node-red does not seem to change anything.

So perhaps I should punt... and ask this community if they have another solution for sending a text string payload to the rpi4 audio output (either hdmi or headphone jack)? There seem to be lots of solutions to playing audio files, or sending a string for Alexa to announce, but not much for native pi4 audio from a text string.

Hello,
You can use

To generate text to speech audio directly from nodered on a pi and than use any of the audio playing nodes to play it. Quality with pico2wave should also be a lot cleaner than espeak.

Johannes

Don't know if it makes a diff but I always put bash extra parameters like -ven etc in the command - not as a suffix.

I always add a space at the end as well

This works for me

image

I hope one of the suggestions has you working but in case not, I'll ask how you are running NR. Is it from a systemd service? If so, can we see the contents of the service file? Of particular interest are the "User=" and "Group=" lines under [Service]. If these don't specify your userid and group then NR is likely running as root and it won't get the same access your login has.

If you are running NR from your command line then you need to log out and back in before your audio group addition will take effect. But that raises the question of why you'd add yourself to the audio group if the command already worked from the command line without it?

Sorry, work is getting in the way so I've not had a chance to get back to sorting this out...

Yes, and the user and group are mine...

# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html

[Service]
Type=simple
# Run as normal pi user - change to the user name you wish to run Node-RED as
User=srickus
Group=srickus
WorkingDirectory=/home/srickus

Environment="NODE_OPTIONS=--max_old_space_size=2048"
# uncomment and edit next line if you need an http proxy
#Environment="HTTP_PROXY=my.httpproxy.server.address"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
# uncomment next line if you need to wait for time sync before starting
#ExecStartPre=/bin/bash -c '/bin/journalctl -b -u systemd-timesyncd | /bin/grep -q "systemd-timesyncd.* Synchronized to time server"'

ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
RestartSec=20
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog

[Install]
WantedBy=multi-user.target

Good question... desparation?

Ok, I think I see what you did there -- are those double quotes that you are using to surround the payload? And is this the way the exec node really works?!?

I guess I thought it was more sophisticated than just pasting some strings together before calling the command line processor, but perhaps not. What happens if the payload has double quotes inside it?

It's just what I tried that works - your working command line shows quotes so I put them in in the exec node.

No idea but not going to happen in this scenario :slight_smile:

Steve, what is in the msg payload going into the exec node? When you check off +Append msg.payload the format ot what gets used by the exec is

  1. everything in Command (which could include options)
  2. anything in msg.payload IF +Append is checked
  3. anything in extra input parameters

Thanks Paul, I tried as you and Simon suggested to try and insert the payload between double quotes after the command and options:

SS, DD... ah well, it was worth the try.

Looks like this is my next best option -- even though I am not as keen on generating binary audio data and passing it to some player.

It's not that bad :wink:
The audio that is generated by Pico2wave can be output as a buffer within the flow and passed directly to for example a sox play node. This way no audio gets actually saved on your device. Only difference would be that you have 2 instead of one node. And I think that is what espeak is doing behind the scenes anyway. They generate an audio buffer and than call some audio player library, you just don't get to see it.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.