How to get text to speech and report it

What the...

I think you misunderstood what the OP is after :slight_smile:

They'd like to to be able to access a sound sample of the text to speech block not just hear the sound

A reporter (round block) reports a value that another block can use as an input

Could you show me the code so I can test it?

I just use someone's contrib node in NodeRED

This is the node I use with the TTS Service using Google (without credentials) setting

GitHub - Supergiovane/node-red-contrib-tts-ultimate: This node transforms a text into a speech audio. You can hear the voice natively through Sonos or external players.

I've no idea how it works but maybe if you explore the source code for it you could work it out

[edit] I've glanced thru its code and I "think" that its using a Google translation API to do the conversion - but I can't work out the details so far

There's a lot of noise when you try and search for free text to speech API :frowning:

[edit2] Made some progress :slight_smile:

provide a free service but it does require signing up and getting a key
Which is fine for personal projects but not good for public ones
I've got as far as this with it
image

I think I just need to work out how to make Snap! play the returned data as a sound

[edit3] 26Jan2022
Well, one issue is that the url block returns at UTF-16 (I think) encoded string and that is no good for binary data such as an audio wav file

So I came up with this (always remember I know very little about JavaScript) that seems to return the contents of the wav file as a list of binary values and AFAICT, the list is the same data that I get if I use the same URL in my browser and download the result

VoiceRSS script pic

But I cannot get it to playback properly in Snap!

I'm obviously missing something somewhere :frowning:

maybe code in something like SAM (software automatic mouth)

You may try "b64" options...

Ouptut seems to be a RIFF, but untitled script pic (1)
probably require only the data (samples) part of the RIFF.

Victory is mine :slight_smile:

So as before, this JavaScript will return the contents of the generated wav file

audioJS

(Just need to add your Voice RSS key as mentioned in previous post)

Then it turns out the audio data is from item 47 to the end of the file (should work for any reasonable TTS request)

so
TTS_textToSpeech_sound script pic

(I've got a more complicated version that will handle 16bits if needed)

convert16bit
or with custom reporters

TTS_textToSpeech_sound script pic (3)

And then we can convert the samples into a Snap! sound :slight_smile:

TTS_textToSpeech_sound script pic (1)