Added Node-RED example

This commit is contained in:
Michael Hansen
2019-05-05 14:47:21 -04:00
parent f16691fdd6
commit 647ff7e3f0
5 changed files with 234 additions and 1 deletions
+1 -1
View File
@@ -841,7 +841,7 @@ def add_ws_event(text: str):
queue.put(text)
@sockets.route("/events/intent")
@sockets.route("/api/events/intent")
def api_events_intent(ws) -> None:
# Add new queue for websocket
q = GQueue()
+5
View File
@@ -0,0 +1,5 @@
# Node-RED Examples
This directory contains two example Node-RED flows for Rhasspy. They assume Rhasspy is running on the localhost at port 12101. See the `run-nodered.sh` script for the Docker command to start Node-RED.
Both example flows use the websocket connection available at `/api/events/intent` to receive intents as Rhasspy recognizes them. The `/api/text-to-speech` endpoint in Rhasspy is also used to provide basic feedback.
+93
View File
@@ -0,0 +1,93 @@
[
{
"id": "2f1e41c5.19c21e",
"type": "tab",
"label": "Rhasspy Example",
"disabled": false,
"info": ""
},
{
"id": "5b0fc170.50ca98",
"type": "websocket in",
"z": "2f1e41c5.19c21e",
"name": "rhasspy",
"server": "63453288.fa038c",
"client": "",
"x": 150,
"y": 100,
"wires": [
[
"7ed528d3.d8a79"
]
]
},
{
"id": "7ed528d3.d8a79",
"type": "switch",
"z": "2f1e41c5.19c21e",
"name": "intent filter",
"property": "intent.name",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "ChangeLightColor",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 230,
"y": 200,
"wires": [
[
"2d6e81cb.099e56"
]
]
},
{
"id": "1cf9bec4.4449d1",
"type": "http request",
"z": "2f1e41c5.19c21e",
"name": "text to speech",
"method": "POST",
"ret": "txt",
"paytoqs": false,
"url": "http://localhost:12101/api/text-to-speech",
"tls": "",
"proxy": "",
"authType": "basic",
"x": 440,
"y": 340,
"wires": [
[]
]
},
{
"id": "2d6e81cb.099e56",
"type": "template",
"z": "2f1e41c5.19c21e",
"name": "light text",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "The {{ slots.name }} is now {{ slots.color }}.",
"output": "str",
"x": 300,
"y": 280,
"wires": [
[
"1cf9bec4.4449d1"
]
]
},
{
"id": "63453288.fa038c",
"type": "websocket-listener",
"z": "",
"path": "ws://localhost:12101/api/events/intent",
"wholemsg": "true"
}
]
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
docker run -it --network host nodered/node-red-docker:latest
+133
View File
@@ -0,0 +1,133 @@
[
{
"id": "2f1e41c5.19c21e",
"type": "tab",
"label": "Rhasspy Example Flow 1",
"disabled": false,
"info": ""
},
{
"id": "63453288.fa038c",
"type": "websocket-listener",
"z": "",
"path": "ws://localhost:12101/api/events/intent",
"wholemsg": "true"
},
{
"id": "5b0fc170.50ca98",
"type": "websocket in",
"z": "2f1e41c5.19c21e",
"name": "rhasspy",
"server": "63453288.fa038c",
"client": "",
"x": 150,
"y": 100,
"wires": [
[
"7ed528d3.d8a79"
]
]
},
{
"id": "7ed528d3.d8a79",
"type": "switch",
"z": "2f1e41c5.19c21e",
"name": "intent filter",
"property": "intent.name",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "GetTime",
"vt": "str"
},
{
"t": "eq",
"v": "ChangeLightState",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 340,
"y": 200,
"wires": [
[
"b4beb082.843988"
],
[
"2d6e81cb.099e56"
]
]
},
{
"id": "1cf9bec4.4449d1",
"type": "http request",
"z": "2f1e41c5.19c21e",
"name": "text to speech",
"method": "POST",
"ret": "txt",
"paytoqs": false,
"url": "http://localhost:12101/api/text-to-speech",
"tls": "",
"proxy": "",
"authType": "basic",
"x": 700,
"y": 240,
"wires": [
[]
]
},
{
"id": "2d6e81cb.099e56",
"type": "template",
"z": "2f1e41c5.19c21e",
"name": "light text",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "Turning {{ slots.state }} the {{ slots.name }}.",
"output": "str",
"x": 520,
"y": 340,
"wires": [
[
"1cf9bec4.4449d1",
"19c43cb6.6e805b"
]
]
},
{
"id": "19c43cb6.6e805b",
"type": "debug",
"z": "2f1e41c5.19c21e",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 730,
"y": 320,
"wires": []
},
{
"id": "b4beb082.843988",
"type": "function",
"z": "2f1e41c5.19c21e",
"name": "time text",
"func": "var timeString = new Date().toLocaleTimeString([],\n{\n hour: \"2-digit\", \n minute: \"2-digit\",\n hour12: true\n})\n\nreturn {\n payload: \"It is \" + timeString\n}",
"outputs": 1,
"noerr": 0,
"x": 520,
"y": 140,
"wires": [
[
"1cf9bec4.4449d1"
]
]
}
]