# Ggwave to wav/mp3 buffer

**URL:** <https://discourse.nodered.org/t/ggwave-to-wav-mp3-buffer/58656>\
**Category:** General\
**Created:** [19 February 2022 18:41 UTC](https://discourse.nodered.org/t/ggwave-to-wav-mp3-buffer/58656 "2022-02-19T18:41:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [19 February 2022 18:41 UTC](https://discourse.nodered.org/t/ggwave-to-wav-mp3-buffer/58656/1 "2022-02-19T18:41:14Z")

</div>

A while back i created a node [minimodem](https://discourse.nodered.org/t/announce-node-red-contrib-minimodem/29569) which was using an old cli application for (de)coding strings to audio...  
This only worked on the server-side, playing/listening on a default audio device. It runs great but I need something different now...

I want to utilize [ggwave](https://github.com/ggerganov/ggwave/) to create the same system but so that the audio is being played/listened by the node-red dashboard...  
I got in a problem where i don't know how to convert ggwave.encode waveform to buffer so i can send it to an audio out node..  
Here is the function i have:

```auto
[
    {
        "id": "54eedcef98ce14ab",
        "type": "function",
        "z": "6b666f2f1c1a7887",
        "name": "working",
        "func": "var factory = ggwave\nvar waveform\nvar parameters \nvar instance\nfactory().then(function (ggwave) {\n var parameters = ggwave.getDefaultParameters();\n var instance = ggwave.init(parameters);\n var payload = 'hel';\n var waveform = ggwave.encode(instance, payload, ggwave.TxProtocolId.GGWAVE_TX_PROTOCOL_AUDIBLE_FAST, 10);\n node.send({ payload: waveform})\n});\n\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [
            {
                "var": "ggwave",
                "module": "ggwave"
            }
        ],
        "x": 320,
        "y": 240,
        "wires": [
            [
                "3311501266b3c615"
            ]
        ]
    }
]

```

The output is a string with random numbers:

> 124,111,0,0,28,0,0,0,0,0,0,0,0,0,0,0,124,111,0,0,28,0,0,0,94,59,-111,55,-100,-41,22,-72,100,82,-64,-72,118,50,18,-71,-104,105,50,-71,63,-14,58,-71,-124,-90,42,-71,-69,62,5,-71,-48,-26,-92,-72,-49,93,-30,-73,-56,76,-104,55,-45,121,77,56,116,117,-128,56,44,14,103,56....

I tried to parse the webpage [example javascript](https://github.com/ggerganov/ggwave/blob/master/examples/ggwave-js/index-tmpl.html) to node-red but figured out that the script is utilizing AudioContext(Web Audio API) that i remember does not work in node-red...

Does anyone have any solution?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 February 2022 21:08 UTC](https://discourse.nodered.org/t/ggwave-to-wav-mp3-buffer/58656/2 "2022-02-19T21:08:00Z")

</div>

> [@lizzardguki](#):
>
> The output is a string with random numbers:

The output is actually an int8array

You can convert it using `Buffer.from()`

e.g...

```auto
var factory = ggwave
factory().then(function (ggwave) {
    var parameters = ggwave.getDefaultParameters();
    var instance = ggwave.init(parameters);
    var waveform = ggwave.encode(instance, msg.payload, ggwave.TxProtocolId.GGWAVE_TX_PROTOCOL_AUDIBLE_FAST, 10);
    var buf = Buffer.from(waveform);
    node.send({topic: "wave", payload: buf})
}).catch(function(err) {
    node.error(err, msg);
});

```

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [20 February 2022 14:19 UTC](https://discourse.nodered.org/t/ggwave-to-wav-mp3-buffer/58656/3 "2022-02-20T14:19:46Z")

</div>

I get an error when trying to play it via audio\_out (dashboard) node...  
Catch node does not show any errors from audio\_out node...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 April 2022 14:20 UTC](https://discourse.nodered.org/t/ggwave-to-wav-mp3-buffer/58656/4 "2022-04-21T14:20:13Z")

</div>

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