Timer between node.send(msg1) and msg(2)

I am trying to inject a timer between TTS text for audible output. I have the following nodes set up to turn to set a variable and output a msg for audible on or off. I have noticed that it seems the initial execution of the flow seems to truncate the beginning of the audible text ouput. My nodes are:

image

I have tried to use the following code to pause the output by using a node.send(msg1) and node.send(msg2).

In the flow I have the timer set to 10 seconds and it seems to have no affect. The flow is below. Once again thanks to all who enlighten me.
Regards

image

[
    {
        "id": "0ee225efc8925baa",
        "type": "ui_switch",
        "z": "d77d303.180d8d",
        "g": "c7cd7c2d1b8d9238",
        "name": "Audible",
        "label": "<font size = 5> Audible",
        "tooltip": "<font size = 4> Enable Disable Audible Output for vision impaired",
        "group": "e357ef02.ef3cb",
        "order": 1,
        "width": "6",
        "height": "1",
        "passthru": true,
        "decouple": "false",
        "topic": "audible",
        "topicType": "str",
        "style": "",
        "onvalue": "1",
        "onvalueType": "num",
        "onicon": "fa-low-vision fa-2x",
        "oncolor": "red",
        "offvalue": "0",
        "offvalueType": "num",
        "officon": "fa-low-vision fa-2x",
        "offcolor": "gray",
        "animate": true,
        "className": "",
        "x": 380,
        "y": 260,
        "wires": [
            [
                "c2742cad0e367d40"
            ]
        ]
    },
    {
        "id": "c2742cad0e367d40",
        "type": "function",
        "z": "d77d303.180d8d",
        "g": "c7cd7c2d1b8d9238",
        "name": "function 2",
        "func": "var audible = msg.payload\n    if (audible === 0){\n    global.set('audible', 0)\n    msg = {payload:'Audible Off'}\n    return msg\n}\nif (audible === 1) {\n    global.set('audible', 1)    \n    var msg1 = { payload: '' }    \n    var msg2 = { payload: 'Audible On'}\n    node.send(msg1)\n    new Promise(resolve => setTimeout(resolve, 10000));\n    node.send(msg2)\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 580,
        "y": 260,
        "wires": [
            [
                "d30e5efcf5ab139c"
            ]
        ]
    },
    {
        "id": "d30e5efcf5ab139c",
        "type": "ui_audio",
        "z": "d77d303.180d8d",
        "g": "c7cd7c2d1b8d9238",
        "name": "",
        "group": "e357ef02.ef3cb",
        "voice": "Google US English",
        "always": true,
        "x": 760,
        "y": 260,
        "wires": []
    },
    {
        "id": "e357ef02.ef3cb",
        "type": "ui_group",
        "name": "Radios - Control",
        "tab": "4bc17c6e.b74934",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": true,
        "className": ""
    },
    {
        "id": "4bc17c6e.b74934",
        "type": "ui_tab",
        "name": "Station",
        "icon": "fa-tachometer",
        "order": 10,
        "disabled": false,
        "hidden": false
    }
]

To avoid a concurrency situation where multiple messages arrive in quick succession at the input of the function node - you would be better off having no delay and instead, add a delay node after the function node, set to rate limit mode.

However, if you insist on a delay in the function node - you need to await.

await new Promise(r => setTimeout(r, 10000));
1 Like

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