Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
908 views
in Technique[技术] by (71.8m points)

javascript - Google Translate API - No Access Control Origin with Text to Speech

I posted this question on SO to get Google Translate Text-To-Speech to work.

Google Translate API text-to-speech: http requests forbidden

I was told I needed a key and to enable billing. I've since done that. I know billing is enabled because, using their specified endpoint for words-only translations (not narrated speech) (GET https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world), I'm able to get a response both in DHC and in my application $.get:

enter image description here

In my original question (above), I was told If I get an API key, I would no longer be blocked from getting text-to-speech. I tested the request for Text-to-speech in DHC and Postman:

https://translate.google.com/translate_tts?key=myKeyHere&ie=utf-8&tl=zh-CN&q=你好

And got a 200:

enter image description here

Excellent. However, in my application, I make a get request:

    $.get('https://translate.google.com/translate_tts?key='+myKey+'&ie=utf-8&tl=en&q=Hello+world',
        function (returned_data) {

I get blocked:

No 'Access-Control-Allow-Origin' header

Why is this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...