Using Amazon Polly with Node-Red

Polly Diagram

Amazon Polly and Node-Red. This was far easier to get going than any Alexa skill I tried to do. I just came across this the other day on Scargill’s Tech blog.

Amazon Polly is a service that turns text into lifelike speech. … With Amazon Polly, you only pay for the number of characters you convert to speech, and you can save and replay Amazon Polly’s generated speech.”

Basically you feed Polly SSML text and it returns it in spoken form as an MP3 (or other format). Sweet, I can give my server/Node-Red a voice! Not sure my wife will like this but it will actually server a valid purpose. I was admitted to the hospital (again) for a short three-day stay recently and while I was admitted (and loaded up on drugs) my server closet reached my maximum set temperature… and issued the text alert 187 times. Now I can have the server annunciate that the closet needs to be opened. I could add my wife’s number to the SMS list but that will fail, lol. Simply saving the MP3 on the server and having it be played back works just great.

I am sure you can tap into the API many other ways, and use Polly many other ways, but the simplest way was my path. I just logged into the Amazon Polly Developer console and slapped some text in the input box. It spit out an MP3 and I saved it. The catch here is that the free tier of the Polly program only lasts 12 months, then you get charged. Its super cheap though, $4 per 1 million characters. The free tier is 4 million per month (for 12 months). From what I have read Polly will search the cloud to see if the file already exists. If it does it pulls it down, if it doesn’t it creates it (and counts agains the character limit) and pulls it down. Is this for “the cloud” or your account? Dunno. Still pretty cheap.

I have circumvented the whole thing (for now). I don’t really plan on (or have the need to) generating Polly files on the fly. What works for me is as I said, just slapping a ton of phrases I think I’ll need into Polly and saving the files for later. I’m cool with that.

But, there is a node for NR that will generate Polly files for you on the fly, and/or pull down the ones already generated. I mentioned I found Polly on Scargill’s blog, he also used NR to play with Polly. He had to do it the hard way. Three days ago the node was made. Definitely check out his blog even if you just use the node. Its all good info.

Install node-red-contrib-polly-tts

npm install node-red-contrib-polly-tts

The node looks pretty simply to use (I have not used it). You need to add your Amazon Polly API credentials to the node. The input gets TTS’d and the file saved. If the text has already been converted no Polly call is made and just the file served. So it looks like it stores all the Polly MP3s for you locally. Sweet.


Discover more from Its_All.Lost

Subscribe to get the latest posts sent to your email.

Leave a Reply