How to access Scratch TTS?

how do I use the scratch TTS api in snap?
by this i mean the api for speak []
which is https://synthesis-service.scratch.mit.edu/synth?locale=LOCALE&gender=GENDER&text=TEXT

yes i know url [] exists, but i need a way to make it a sound.

play sound (url [https://synthesis-service.scratch.mit.edu/synth?locale=LOCALE&gender=GENDER&text=TEXT]) obviously won't work, because what url [https://synthesis-service.scratch.mit.edu/synth?locale=LOCALE&gender=GENDER&text=TEXT] is spitting out is MP3 data and not a sound.

2 hours, no response... :confused:

Reminds me of

Snap! does have a text to speech library - maybe you should check that out. If that is not what you are looking for, I am afraid I can't help you.

This is actually more complicated than it may seem. I tried just creating a new sound that points to the url, but it won't play due to the CORS policy, which doesn't really make much sense because you can get the file data with a javascript fetch method.

It is important to note that this forum is not an instant messaging platform, and some posts can take days for someone to respond. Not to mention, it's sunday, and I've noticed that there is less activity on the forum on sundays than any other day of the week.

What you're asking for is actually something pretty complicated (because scratch is somehow blocking direct audio playback, but not regular fetching), and takes more knowledge of snap and javascript for someone to create (which rules out anyone who hasn't touched javascript), so you just have to be patient.

Edit: I'm also not entirely sure if you're technically even allowed to use this, since it's a scratch service that is meant to only be used on scratch (and scratch mods), not other websites.

that has a delay, and the pitch doesn't work

What do you mean, it work for me...

Different browsers on different devices may do other things. Browsers are very inconsistent.

I think it relies on the operating system's TTS. The voice continues speaking when you close the tab, and the voice is different with the same browser on different operating systems.

I believe this should work

resource loading script pic

Unfortunately that does not work with the scratch tts, because CORS is blocking it. What's strange is that you can get the raw mp3 data with a simple fetch (basically just the (url []) block), so theoretically you can turn that into a data url and then use that.

Apart from the problem of the sideloading of the scratch TTS service...

It should be as simple as


but there is an error in rs_load_sound and only global variable is handled properly.

Something more convoluted works for me

rs_load_sound(url, varName) ... sound
Should the var name be sound data to match the script var?

The actual definition in the second script pic has a lot more than the first script pic with the definition.

(I love smart script pics)

Now we need smart Snapblocks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.