Skip to content

Instantly share code, notes, and snippets.

@DIYtechie
Last active June 27, 2021 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DIYtechie/ac3d25616af3030bdc859762bd2e9e86 to your computer and use it in GitHub Desktop.
Save DIYtechie/ac3d25616af3030bdc859762bd2e9e86 to your computer and use it in GitHub Desktop.
Store and play wavenet voice message

This flow stores a custom Google Wavenet voice message locally and plays it on your Sonos and Google Cast devices.

Flow flow

(If you are satisfied with the standard node-red-contrib-cast voices and only use Google Cast speakers, this flow is not relevant for you.)


Copy the flow below to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option.

Remember to install the required nodes before importing this flow into Node-RED (check out Node types box on this page)

[
{
"id": "718be20e.bb9d8c",
"type": "tab",
"label": "Wavenet text-to-speech",
"disabled": false,
"info": ""
},
{
"id": "1974b70a.6d0749",
"type": "comment",
"z": "718be20e.bb9d8c",
"name": "Link to latest version of this flow: https://flows.nodered.org/flow/ac3d25616af3030bdc859762bd2e9e86",
"info": "",
"x": 370,
"y": 40,
"wires": []
},
{
"id": "db4837d0.7098c8",
"type": "inject",
"z": "718be20e.bb9d8c",
"name": "Add new",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 150,
"y": 150,
"wires": [
[
"4ad36ce3.f39424"
]
]
},
{
"id": "4d38f468.68e2fc",
"type": "function",
"z": "718be20e.bb9d8c",
"name": "voice message",
"func": "msg.payload = \"It works!\"\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 510,
"y": 150,
"wires": [
[
"be528c50.85b7"
]
]
},
{
"id": "be528c50.85b7",
"type": "wavenet",
"z": "718be20e.bb9d8c",
"name": "Wavenet",
"key": "",
"voice": "kimberly",
"rate": "1.0",
"pitch": "0",
"volume": "0",
"sample": "24000",
"encoding": "MP3",
"x": 690,
"y": 150,
"wires": [
[
"69babc75.400154"
]
]
},
{
"id": "d566324c.43019",
"type": "comment",
"z": "718be20e.bb9d8c",
"name": "Wavenet voice - Sign in to Google Developer Console to get a Speech API key.",
"info": "",
"x": 340,
"y": 100,
"wires": []
},
{
"id": "68b49607.9786c8",
"type": "file",
"z": "718be20e.bb9d8c",
"name": "store voice message as mp3",
"filename": "",
"appendNewline": true,
"createDir": true,
"overwriteFile": "true",
"encoding": "none",
"x": 420,
"y": 270,
"wires": [
[
"268259ea.0fdc76"
]
]
},
{
"id": "a21d683f.fd0798",
"type": "comment",
"z": "718be20e.bb9d8c",
"name": "store voice message locally",
"info": "",
"x": 180,
"y": 220,
"wires": []
},
{
"id": "bba3a3e4.2a697",
"type": "cast-to-client",
"z": "718be20e.bb9d8c",
"name": "insert your speaker IP here",
"url": "",
"contentType": "",
"message": "",
"language": "",
"ip": "192.168.3.67",
"port": "",
"volume": "80",
"x": 730,
"y": 500,
"wires": [
[]
]
},
{
"id": "69babc75.400154",
"type": "function",
"z": "718be20e.bb9d8c",
"name": "create filepath",
"func": "let filename = flow.get(\"filename\");\nmsg.filename = \"/data/getfile/\" + filename + \".mp3\"\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 170,
"y": 270,
"wires": [
[
"68b49607.9786c8"
]
]
},
{
"id": "268259ea.0fdc76",
"type": "function",
"z": "718be20e.bb9d8c",
"name": "insert your Node-RED IP here",
"func": "let NodeREDIP = \"http://192.168.3.62:1880\"\nlet filename = flow.get(\"filename\");\nmsg.url = NodeREDIP + \"/getfile/\" + filename + \".mp3\"\nmsg.contentType = \"audio/mp3\"\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 420,
"y": 500,
"wires": [
[
"bba3a3e4.2a697",
"a1206f4b.22b66"
]
]
},
{
"id": "6fb3fa41.a6bc94",
"type": "http response",
"z": "718be20e.bb9d8c",
"name": "http response",
"statusCode": "",
"headers": {
"content-type": "audio/mpeg"
},
"x": 780,
"y": 390,
"wires": []
},
{
"id": "89bde581.8f0768",
"type": "file in",
"z": "718be20e.bb9d8c",
"name": "get file",
"filename": "",
"format": "",
"chunk": false,
"sendError": false,
"x": 620,
"y": 390,
"wires": [
[
"6fb3fa41.a6bc94"
]
]
},
{
"id": "17ec33e4.acd1cc",
"type": "template",
"z": "718be20e.bb9d8c",
"name": "extract requested filepath",
"field": "filename",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "/data/getfile/{{req.params.name}}",
"x": 430,
"y": 390,
"wires": [
[
"89bde581.8f0768"
]
]
},
{
"id": "2ca07166.b72fde",
"type": "http in",
"z": "718be20e.bb9d8c",
"name": "listen for http requests",
"url": "/getfile/:name",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 190,
"y": 390,
"wires": [
[
"17ec33e4.acd1cc"
]
]
},
{
"id": "4ad36ce3.f39424",
"type": "change",
"z": "718be20e.bb9d8c",
"name": "desired filename",
"rules": [
{
"t": "set",
"p": "filename",
"pt": "flow",
"to": "wavenet-test",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 320,
"y": 150,
"wires": [
[
"4d38f468.68e2fc"
]
]
},
{
"id": "d77e7e5b.e5ba5",
"type": "inject",
"z": "718be20e.bb9d8c",
"name": "Play",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 140,
"y": 500,
"wires": [
[
"268259ea.0fdc76"
]
]
},
{
"id": "e35227df.9d18b8",
"type": "comment",
"z": "718be20e.bb9d8c",
"name": "Make local voice message available to smart speakers via http",
"info": "",
"x": 290,
"y": 340,
"wires": []
},
{
"id": "502ffa4e.5566c4",
"type": "comment",
"z": "718be20e.bb9d8c",
"name": "Play locally stored wavenet voice message",
"info": "",
"x": 220,
"y": 450,
"wires": []
},
{
"id": "6cb9ad9f.059294",
"type": "sonos-universal",
"z": "718be20e.bb9d8c",
"confignode": "",
"compatibilityMode": false,
"command": "group.play.notification",
"state": "",
"stateType": "str",
"name": "",
"x": 710,
"y": 550,
"wires": [
[]
]
},
{
"id": "a1206f4b.22b66",
"type": "change",
"z": "718be20e.bb9d8c",
"name": "adapt for sonos",
"rules": [
{
"t": "move",
"p": "url",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "volume",
"pt": "msg",
"to": "50",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 470,
"y": 550,
"wires": [
[
"6cb9ad9f.059294"
]
]
}
]
@joseluisgodinho
Copy link

Hello
I was looking for this kind of node red programam, for that I thank you
Albeit I am not able to get it to work.
Am using the node Sonos ver 4.1.0 , and it does not recognise the http link.

Anther question is that if I connect the output of the wavenet, for sure using the change node as per your exemple, I cannot get my sonos working either.

The erro is not in the configuration of the nodes, because i got the mp3 file from wave net and also manage t get the status of the Sonos.

I suspected that could be the syntax out of the node you called tts + reset volume
i have tested

@DIYtechie
Copy link
Author

I think the Sonos node syntax has been changed since I made the flow. Still works with the old Sonos node.

Will try updating my Sonos nodes and see if there is anything I need to change.

@DIYtechie
Copy link
Author

Should work with the latest version of node-red-contrib-sonos-plus now.

@joseluisgodinho
Copy link

joseluisgodinho commented Jul 14, 2020 via email

@DIYtechie
Copy link
Author

Yes, latest version of this flow (above) 👆🏻😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment