Google Translate API text-to-speech: http requests

2019-04-28 09:17发布

问题:

I am making a language learning web app that when you hover over the word, it pronounces it for you. I'd like to access the native speaker translations from Google Translate API.

I've found this resource which gives http://translate.google.com/translate_tts as the base URL and tl for target language and q for the query string.

This works awesome when I just access it in the browser, http://translate.google.com/translate_tts?tl=zh-CN&q=你好, but any httprequests for my app return a 403 Forbidden error.

localhost:~ me$ wget "http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=hello+world" --2015-06-02 11:02:06-- http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=hello+world Resolving translate.google.com... 173.194.123.38, 173.194.123.36, 173.194.123.32, ... Connecting to translate.google.com|173.194.123.38|:80... connected. HTTP request sent, awaiting response... 403 Forbidden 2015-06-02 11:02:07 ERROR 403: Forbidden.

Is there a formal Google API for text-to-speech associated with their payment plans for traditional Google Translate API that I'm just not finding? Or is there a way to get and play this audio somehow?

回答1:

That resource is dated. Google deprecated free access to the language translate api. Now an API key is needed. The api is also now in V2.

Without an api key you will receive the 403 forbidden error.

More information here: https://cloud.google.com/translate/docs



回答2:

You can get anything sound, I found it: https://translate.google.com.vn/translate_tts?ie=UTF-8&q=ANYTHING_TEXT&tl=en&client=tw-ob Note: client=tw-ob