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 )
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
Entity(1).sound = channel
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.
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