Using gTTS with python-venv node (Text-to-Speech)

Also introduced in my article below:
In English: https://404background.com/en/programming/en-python-gtts/
In Japanese: https://404background.com/program/python-gtts/

In this page, I tried using gTTS (Google Text-to-Speech) with the python-venv node in Node-RED.
Using gTTS, you can generate an audio file that speaks text.

Just follow the steps below to make it available.

  1. Install gTTS with the pip node.
  2. Run gtts-cli.exe using the venv-exec node.

The following flow can be used to execute gTTS. image

If you pass only text, for example, you can generate an audio file of the text entered at the dashboard node.
I used template nodes to pass the arguments of the executable. image image

In addition, connecting to a node that plays audio, the generated audio file can be played.

[{"id":"ddfe80c74af06b2c","type":"pip","z":"d6fad9e77ecc8414","venvconfig":"4657b6fbdbaf6f7e","name":"","arg":"gTTS","action":"install","tail":false,"x":1130,"y":620,"wires":[["3a1061bc1379d5a3"]]},{"id":"2018adf11f6fc54a","type":"inject","z":"d6fad9e77ecc8414","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":980,"y":620,"wires":[["ddfe80c74af06b2c"]]},{"id":"3a1061bc1379d5a3","type":"debug","z":"d6fad9e77ecc8414","name":"debug 150","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1290,"y":620,"wires":[]},{"id":"b2d40b173b47da0d","type":"venv-exec","z":"d6fad9e77ecc8414","name":"","venvconfig":"4657b6fbdbaf6f7e","mode":"execute","executable":"gtts-cli.exe","arguments":"'hello' --output hello.mp3","x":1130,"y":680,"wires":[["8c8a3251975e3715"]]},{"id":"13d347fb7f4abb85","type":"inject","z":"d6fad9e77ecc8414","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":980,"y":680,"wires":[["b2d40b173b47da0d"]]},{"id":"8c8a3251975e3715","type":"debug","z":"d6fad9e77ecc8414","name":"debug 155","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1290,"y":680,"wires":[]},{"id":"0372630ba5757ebc","type":"venv-exec","z":"d6fad9e77ecc8414","name":"gTTS","venvconfig":"4657b6fbdbaf6f7e","mode":"execute","executable":"gtts-cli.exe","arguments":"","x":1330,"y":880,"wires":[["dc672ce66ab88f82"]]},{"id":"5cd69008f7cd2d7b","type":"inject","z":"d6fad9e77ecc8414","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Hello, World!","payloadType":"str","x":970,"y":760,"wires":[["415fae35ac7b5a75"]]},{"id":"dc672ce66ab88f82","type":"debug","z":"d6fad9e77ecc8414","name":"debug 324","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1490,"y":880,"wires":[]},{"id":"415fae35ac7b5a75","type":"template","z":"d6fad9e77ecc8414","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"'{{payload}}' --output voice.mp3","output":"str","x":1140,"y":760,"wires":[["4d37f247b6c5a965","4c88700fb753b6da"]]},{"id":"b92475c110bb9658","type":"inject","z":"d6fad9e77ecc8414","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Nice to meet you.","payloadType":"str","x":980,"y":840,"wires":[["415fae35ac7b5a75"]]},{"id":"96e2d1b347433bc4","type":"template","z":"d6fad9e77ecc8414","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"'{{payload}}' --output voice_ja.mp3 --lang ja","output":"str","x":1160,"y":880,"wires":[["0372630ba5757ebc"]]},{"id":"c94f4c2cbf5e7976","type":"inject","z":"d6fad9e77ecc8414","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"こんにちは","payloadType":"str","x":960,"y":880,"wires":[["96e2d1b347433bc4"]]},{"id":"07db4e715e3cd7a0","type":"inject","z":"d6fad9e77ecc8414","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"はじめまして","payloadType":"str","x":970,"y":920,"wires":[["96e2d1b347433bc4"]]},{"id":"4d37f247b6c5a965","type":"debug","z":"d6fad9e77ecc8414","name":"debug 325","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1310,"y":720,"wires":[]},{"id":"4c88700fb753b6da","type":"change","z":"d6fad9e77ecc8414","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"\"","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1340,"y":760,"wires":[["0372630ba5757ebc"]]},{"id":"4657b6fbdbaf6f7e","type":"venv-config","venvname":"pyenv","version":"default"}]

Flow Info

Created 4 months, 2 weeks ago
Rating: not yet rated

Actions

Rate:

Node Types

Core
  • change (x1)
  • debug (x4)
  • inject (x6)
  • template (x2)
Other

Tags

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