Hey!
Has anyone managed to successfully integrate Google’s text to speech in a Corona app?
I came across this post: http://forums.coronalabs.com/topic/36383-text-to-speech-in-corona-sdk/ It demonstrates a (unofficial) way to use google text to speech in Corona. I’ve implemented it and it works fine in the simulator, but when running on an Android device no voice files are received.
It works fine on the device if I use any URL other than google’s and download some random mp3, so it must be that Google is protecting theirs. I came accross some posts pointing out that the headers for the request should contain an empty referer, which I also tried, as well as faking the user agent.
Any ideas?
Thanks!
local function downloadSpeech(language, text, filename, instant) local function networkListener(event) if ( event.isError ) then print( "Network error - download failed" ) elseif ( event.phase == "began" ) then print( "Progress Phase: began" ) elseif ( event.phase == "ended" ) then print( "Done" ) if language == "spanish" then currentSpanish = audio.loadSound(language .. ".mp3", system.TemporaryDirectory) else currentEnglish = audio.loadSound(language .. ".mp3", system.TemporaryDirectory) end if instant then play(language) end end end local lan = (language == "spanish" and "es") or "en" local params = {} local headers = {} headers["Content-Type"] = "audio/mpeg" headers["Content-Transfer-Encoding"] = "binary" headers["Pragma"] = "no-cache" headers["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)" headers["Referer"] = "\r\n" params.headers = headers params.progress = "download" params.response = { filename = filename .. ".mp3", baseDirectory = system.TemporaryDirectory } network.request("http://www.translate.google.com/translate\_tts?tl=" .. lan .. "&q=" .. text, "GET", networkListener, params ) end
