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

**URL:** <https://discourse.nodered.org/t/node-red-contrib-mic-how-to-use-it/23225>\
**Category:** General\
**Created:** [17 March 2020 10:52 UTC](https://discourse.nodered.org/t/node-red-contrib-mic-how-to-use-it/23225 "2020-03-17T10:52:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hammeronthenet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hammeronthenet/32/29102_2.png) [@hammeronthenet](https://discourse.nodered.org/u/hammeronthenet)\
**Post date:** [17 March 2020 10:52 UTC](https://discourse.nodered.org/t/node-red-contrib-mic-how-to-use-it/23225/1 "2020-03-17T10:52:06Z")

</div>

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

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!!!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 March 2020 11:08 UTC](https://discourse.nodered.org/t/node-red-contrib-mic-how-to-use-it/23225/2 "2020-03-17T11:08:44Z")

</div>

The Info tab for the node is not very informative, but there is more information on the node's [page on npm](https://www.npmjs.com/package/node-red-contrib-mic). However, I note that it has not been maintained in three years so whether it will still work I don't know.

---

<div class="post-metadata">

**Author:** ![hammeronthenet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hammeronthenet/32/29102_2.png) [@hammeronthenet](https://discourse.nodered.org/u/hammeronthenet)\
**Post date:** [17 March 2020 11:21 UTC](https://discourse.nodered.org/t/node-red-contrib-mic-how-to-use-it/23225/3 "2020-03-17T11:21:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 March 2020 12:09 UTC](https://discourse.nodered.org/t/node-red-contrib-mic-how-to-use-it/23225/4 "2020-03-17T12:09:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hammeronthenet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hammeronthenet/32/29102_2.png) [@hammeronthenet](https://discourse.nodered.org/u/hammeronthenet)\
**Post date:** [17 March 2020 12:52 UTC](https://discourse.nodered.org/t/node-red-contrib-mic-how-to-use-it/23225/5 "2020-03-17T12:52:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 March 2020 13:18 UTC](https://discourse.nodered.org/t/node-red-contrib-mic-how-to-use-it/23225/6 "2020-03-17T13:18:20Z")

</div>

> [@hammeronthenet](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![hammeronthenet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hammeronthenet/32/29102_2.png) [@hammeronthenet](https://discourse.nodered.org/u/hammeronthenet)\
**Post date:** [20 March 2020 14:42 UTC](https://discourse.nodered.org/t/node-red-contrib-mic-how-to-use-it/23225/7 "2020-03-20T14:42:06Z")

</div>

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/5014711eafe2b77d554a5ff88eceea48bbb27d6f.png)

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):

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/5/b5a3e4e69628e3369fcb067bd8c8031783a4bcc1.png)

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?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 March 2020 15:53 UTC](https://discourse.nodered.org/t/node-red-contrib-mic-how-to-use-it/23225/8 "2020-03-20T15:53:39Z")

</div>

> [@hammeronthenet](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [20 March 2020 18:11 UTC](https://discourse.nodered.org/t/node-red-contrib-mic-how-to-use-it/23225/9 "2020-03-20T18:11:21Z")

</div>

> [@hammeronthenet](#):
>
> how to use the MIC node stream mode?

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

- _ **Buffer mode** _ [code](https://github.com/MattVador/node-red-contrib-mic/blob/master/node-red-contrib-mic.js#L24):

```auto
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:

```auto
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](https://github.com/ashishbajaj99/mic) NPM library. It is unclear to me what this could be used for ...

Bart
