I need to get (any) OK-response from Yandex SpeechKit.API.
I got API-KEY (valid) and successfully used it and received responses via NodeJS and even GitBash (see links to screens below).
But browsers show me 401:
There're rules for API requests: docs.
My JS code for browsers:
let api_key = '*********c_Ujs9scAhJVVZOs2xjnbvevqj6OFFm';
let params = new URLSearchParams();
const text = 'Привет!';
params.append('text', text);
params.append('voice', 'jane');
params.append('emotion', 'good');
params.append('lang', 'ru-RU');
params.append('speed', '1.0');
params.append('format', 'oggopus');
const fetchButton = document.getElementById("fetchButton");
fetchButton.onclick = () => {
fetch('https://tts.api.cloud.yandex.net/speech/v1/tts:synthesize', {
method: 'POST',
body: params,
mode: "no-cors",
headers: {
//'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Api-Key ' + api_key,
},
}).then((res) => {
console.log(res);
}).catch((err) => {
console.error(`!!! + ${err} + !!!!!!!!`)
});
}
There're code examples for Node and Bash: