Node-red-contrib-mic : how to use it?

Hi all,
this is my first post here, I'm exploring nodered and i'm very happy with it :slight_smile: .

I'm wondering how to use the component in the object ( node-red-contrib-mic ). I'm using it on a Raspberry PI with nodered installed.

I tried with arecord / aplay to record my voice through an USB microphone and everything gone fine.

I tried same hardware parameters on node-red-contrib-mic but I'm unable to work with it.

I created a simple flow with 2 inject nodes (one for the start and one for the stop), a node-red-contrib-mic node and, in output, a debug node "to see what happens".
When I click on start node, Mic node start "recording" but immediatly pass to the next node (the debug node). I think this is wrong, or maybe I don't understand how it works.

Pressing on stop, it stop the recording but nothing else happens.

Can someone explain me what I'm done wrong and/or what I can check?

Thank you in advance!!!

1 Like

The Info tab for the node is not very informative, but there is more information on the node's page on npm. However, I note that it has not been maintained in three years so whether it will still work I don't know.

Hi Colin,
I red it and all what I do seems ok.

My doubt is about streaming output: there's another node that must to be connected to it to permit streaming elaboration? I don't know it.

It could be useful if someone that use this component share a poc on how to use it: the final result could be a stream in msg.payload or something similar imho.

What do you see in the payload if you put it in Stream mode? It says you get a readable stream in the payload when you start recording, whatever that means.

I've got a little enhancement putting a node-red-contrib-wav and settings the output on the mic component to "buffer".

I'm wondering to understand how to work with stream mode.

What do you see in the message? Feed it into a debug node and show us what you see.

Sorry for the delay,
in the meantime I made something working:

image

In detail, I use the file node to save chunks arriving from Mic node (Mic node is setted to "buffer" mode, not stream).
After n block of silence (or pressing the stop node), Mic node stops to send byte to the file.

I realized another subflow, that start when Mic status change, and verify if it is "stopped" , then read the file and do operation with that (in my case, look down, call a wastno-speech-to-text node for STT):

At this point, I'm wondering if there's some node or coding solution to "accumulate" buffer chunks in a variable (delete/write a file it's not a great solution in my opinion...) and then use it directly on STT node.

And also: how to use the MIC node stream mode?

This is the third time I have suggested that a start to understanding this would be to set it to stream mode, feed it into a debug node and start it going. Screenshot (preferably) what you see in the debug node. Expand the contents fully if necessary.

Hi,
I haven't used this node myself, but had a quick look at the source code.

  • Buffer mode code:
    if (node.config.outputPayloadType == "buffer") {
       micAudioStream.on('data', function(data) {
          node.msg.payload = data;
          node.msg.event = "data";
          node.send(node.msg);
       });
    }
    
    Every time the micAudioStream offers an audio chunk, that chunk is immediately send as an output message.
  • Stream mode code:
    micAudioStream.on('startComplete', function() {
       node.log("Stream event startComplete");
       node.status(nodeStatusRecording);
    
       if (node.config.outputPayloadType == "stream") {
          node.msg.payload = micAudioStream;
          node.send(node.msg);
       }
    });
    
    So the micAudioStream needs to be complete and after that the micAudioStream object itself will be send in the output message. That micAudioStream object is based on the mic NPM library. It is unclear to me what this could be used for ...

Bart