Ggwave to wav/mp3 buffer

A while back i created a node minimodem 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 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:

[
    {
        "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 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?

The output is actually an int8array

You can convert it using Buffer.from()

e.g...

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);
});

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

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