Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Text to Speech using Google TTS [IOS Only] — Gideros Forum

Text to Speech using Google TTS [IOS Only]

bowerandybowerandy Guru
edited October 2012 in Code snippets
Hi,

I just thought I'd post this as I thought it was rather cool. Since it uses the Google Translate service it might be possible to do the same thing in a cross platform fashion but using the Hot Wax plugin it was so easy...
function speak(text, lang)
	local textToSend=text:gsub(" ", "+")
	local ttsUrl=string.format("<a href="http://translate.google.com/translate_tts?tl=%s&q=%s"" rel="nofollow">http://translate.google.com/translate_tts?tl=%s&amp;q=%s&quot;</a>, lang or "en", textToSend)
	local ttsData = NSData:dataWithContentsOfURL(NSURL:URLWithString(ttsUrl))
	local avPlayer = AVAudioPlayer:initWithData_error(ttsData, nil) 
	avPlayer:play()
end
 
speak("Heres a bit of fun. Frankly I was amazed at how quickly this rendered, and how good the quality was.")
-- or 
-- speak("Tres bon, mes amis. Ce logiciel est tellement genial!", "fr")
best regards

Likes: atilim

+1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.