Hello Fellow Noderoids,
I initially asked this in Dashboard, but I’m not trying to make it work with Dashboard anymore, and I'm still failing at this.
I am trying to pull audio out of a buffer using an HTTP endpoint, but I am doing something wrong.
My use case is voice notifications played by Pi Zero satellite nodes in various rooms. Initially I had the nodes calling the local Piper AI server themselves, but Piper doesn't like it when it gets multiple concurrent requests, which it will do every time a broadcast goes to all speaker nodes.
Therefore, a more efficient way of doing it is for the main Node-RED to make one call to Piper, and publish the audio to the relevant node(s) via MQTT payload. I can’t get it to work.
I am trying to solve this with a test case. The flow is a modification of something @Steve-Mcl came up with, changed for context.
I have succeeded in testing an HTTP endpoint to send some text; it works. Now I’m trying to do it with a binary buffer. I figure that if I can get the buffer to work, then putting a payload into a buffer is trivial after that.
So, since we need a buffer, there’s an inject node to load a pre-generated WAV into flow.buffer; that's so the endpoint has something to pull.
When called, the HTTP endpoint pulls the audio from the buffer and sticks it in msg.payload, and tags it with a ContentType of audio/wav.
I make that call using the node-red-contrib-play-sound (node) - Node-RED PlaySound node, which shells out to aplay or aplayer of your choice. It is configured to call the HTTP endpoint.
Now, the playback node should work. I know this because there's a second one configured to play the wav file directly, and it does work. The one that doesn't work is the one calling the HTTP endpoint.
Somehow, somewhere along the line, I've misconfigured a thing. Please help.
Here is the flow:
[{"id":"da92c63e371ffa35","type":"file in","z":"287522cb42f89190","name":"","filename":"/home/pinode01/hello.wav","filenameType":"str","format":"","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":290,"y":80,"wires":[["ae842cd82137cd13"]]},{"id":"ce0e015b9c560588","type":"inject","z":"287522cb42f89190","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":180,"wires":[["137433bcd27c6f50"]]},{"id":"86bd43344523cd4c","type":"http in","z":"287522cb42f89190","name":"","url":"/why","method":"get","upload":false,"swaggerDoc":"","x":100,"y":360,"wires":[["7f76adae882b8835"]]},{"id":"7f76adae882b8835","type":"change","z":"287522cb42f89190","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"buffer","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":360,"wires":[["722eb454e42dc823","fd2f78d6299155b3"]]},{"id":"722eb454e42dc823","type":"http response","z":"287522cb42f89190","name":"","statusCode":"","headers":{"content-type":"audio/wav"},"x":490,"y":360,"wires":[]},{"id":"137433bcd27c6f50","type":"http request","z":"287522cb42f89190","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"http://localhost:1880/why","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":250,"y":180,"wires":[["6f26b724287edd74","7e462c00451ddab3"]]},{"id":"d743425956788990","type":"inject","z":"287522cb42f89190","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":80,"wires":[["da92c63e371ffa35"]]},{"id":"ae842cd82137cd13","type":"change","z":"287522cb42f89190","name":"","rules":[{"t":"set","p":"buffer","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":80,"wires":[[]]},{"id":"d72a969579578390","type":"comment","z":"287522cb42f89190","name":"1. Put something in a buffer","info":"","x":160,"y":40,"wires":[]},{"id":"958b3bf0f0af0d6a","type":"comment","z":"287522cb42f89190","name":"3. The HTTP endpoint, pulls the buffer when asked.","info":"","x":230,"y":320,"wires":[]},{"id":"6f26b724287edd74","type":"PlaySound","z":"287522cb42f89190","name":"Play the file as served by the endpoint","playerOptions":"{}","audioURI":"http://localhost:1880/why","options":"{}","x":590,"y":180,"wires":[[]]},{"id":"fd2f78d6299155b3","type":"debug","z":"287522cb42f89190","name":"Just so I can see it being called","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":570,"y":400,"wires":[]},{"id":"7e462c00451ddab3","type":"debug","z":"287522cb42f89190","name":"It looks like this when it comes back","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":580,"y":220,"wires":[]},{"id":"fb20e1880632fd94","type":"comment","z":"287522cb42f89190","name":"2. Call the endpoint and play","info":"","x":160,"y":140,"wires":[]},{"id":"1c71a86a670a0d45","type":"PlaySound","z":"287522cb42f89190","name":"Play the wav file directly","playerOptions":"{}","audioURI":"/home/pinode01/hello.wav","options":"{}","x":550,"y":260,"wires":[[]]}]