Links to URL based Text to Speech?

I’m looking for a URL based text to speech where you can put text in the URL and it will return a text to speech of that text.
Something like this:
www.thisisawebsiteabouttexttospeech.com/text=text_to_turn_into_speech

The issue being, I couldn’t find anything like that. Does anyone know of a site that does this? (im doing this to play it with sound.PlayURL())

Here is an example of a Text-To-Speech script: GitHub - meharryp/GMod-TTS: A text to speech for GMod.

That doesn’t work it seems. When checking to see the sound returned from PlayURL is valid (as seen here),

it always returns false meaning it never gives me anything (I’m testing the addon you sent me to see if it would even work).

Now I don’t know if this is the cause of it, (when I try to access the link)
image
Or it would be the result of something else.

Solutions?

It seems the endpoint has changed over the time, try replacing this line with the code below:
sound.PlayURL( "https://translate.google.com/translate_tts?ie=UTF-8&tl=en-US&client=tw-ob&q=" .. text, "3d", function( sound )

Appears to be working now. But 1 more question, is there a way to change the voice? (for my current purpose, I’m looking for Tom)

Edit: Now that I play around with this more, I discover that when trying to replace the spaces in strings with “%20”, the voice says those even though it’s not supposed too.


But removing the spaces being turned into “%20” just stops it from even working now. Using other characters like underscores doesn’t help either.

With this parameter you can change the language of the speaker and I guess you have to define an ISO code according to the language: ISO 3166-1 - Wikipedia (example for French: fr_FR, British English en_UK, etc.).

Interesting, but one problem. There are multiple American English voices and the one I’m specifically looking for is NextUp-ScanSoft Tom. Is there like any way to change between different American English voices?

(I also edited my reply above of a new issue just as you were typing a reply)

Yes, this mechanism is normally automated when you type a URL into your browser. The URL is encoded if you insert special characters (like spaces). I don’t know if you have to do this on your side or just concatenate the raw string. I can’t test this behavior now because I’m not on a computer.

I doubt this voice exists since it is generated by Google’s servers and it only accepts a change of spoken language and its variants (e.g. British or American English, traditional or simplified Chinese, etc.).

I concatenate the string with spaces replaced as “%20” with the link. Voice says the special characters that aren’t supposed to be said. But if I don’t replace the spaces and leave them as is, well then it just straight up doesn’t work (and I’m still concatenating the string with the link too).

I guess we will have to wait tomorrow then (for me at least, it’s night currently).

I asked a friend to test this code for me and he told me that everything works fine on his side (client-side, gamemode Sandbox), the URL encoding is not necessary. So I guess there is a problem on your side.

local text = "Hello everyone, how are you today?"

sound.PlayURL( "https://translate.google.com/translate_tts?ie=UTF-8&tl=en-US&client=tw-ob&q=" .. text, "", function( channel )
	if IsValid( channel ) then
		channel:Play()
		Entity(1).sound = channel
	end
end )

Odd. Well I don’t really know how to fix this seeing how this is just an issue on my end. Any solutions?

Edit: After testing some more, I found out its working now (even with spaces). But when I input a really long string (~900 characters), it just doesn’t work at all anymore. Is there a solution to it? Or a workaround even?

I’ve had some experience attempting to utilise this unofficial Google endpoint within Garry’s Mod, unfortunately it is not guaranteed to work, and in recent years it has been altered to put up further anti-bot like gates. I believe the word limit currently sits at 100 words, I suppose a workaround for this would be to queue up the requests after splitting up your string; assuming the endpoint actually responds correctly.

In practice, I’ve found the endpoint tends to respond well for some, and not for others; I imagine this is to do with the anti-bot measures, some IP blocks seem to never be able to access this without going through a Captcha gate first.

For a reliable solution, you’ll need to provide a web service like this yourself, which is a different discussion entirely, and for it to be high quality, and natural, this is likely going to cost as you’ll be utilising one of the many cloud based text-to-speech APIs.

Welp, I don’t have the time or money to make/get my own tts API. So I guess splitting the message up is the only workaround. I appreciate yalls help.

Turns out this is also way harder than I thought. Because the only way to get the time length of the sound is after when it has finished playing meaning I can’t add a delay between playing the sounds.

Figured I could use SoundDuration global. But all it does is return 0. And I’m well aware it only does that for non wav files (the file being returned to me is an mp3). So since I can’t even use SoundDuration is there any other way of getting the duration of the sound (or a work around for SoundDuration?) (sound:GetLength() doesn’t even work as intended cause it only gives non zero values after it has finished playing)?
@Florian4016

Yes it’s a well known bug in Garry’s Mod, you can use one of these addons to fix it: Steam Workshop::Linux SoundDuration Fix