J'essaie d'utiliser le service de synthèse vocale Watson dans un code javascript. Cependant, je suis coincé en essayant de le faire fonctionner.Problème d'autorisation pour le script Watson Text to Speech from Java
Si j'utilise le code suivant:
$.ajax({
url: 'https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize',
type: 'POST',
headers: {"Content-Type": "application/json", "Accept": "audio/*", "Authorization": "Basic SomethingSomethingSomething=="},
text: msgData.message[0].cInfo.text,
output: 'output.wav',
success: function() {
console.log("text to voice complete");
var audio = new Audio('output.wav');
audio.play();
}
});
je reçois:
Impossible de charger https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize: Demande champ d'en-tête d'autorisation n'est pas autorisé par Contrôle d'accès-Laissez-têtes dans la réponse preflight.
S'il vous plaît noter que je pourrais facilement obtenir une demande comme ceci fonctionne à partir de Restlet.
Cependant, si je l'utilise:
$.ajax({
url: 'https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize',
type: 'POST',
user: {"something": "something"},
headers: {"Content-Type": "application/json", "Accept": "audio/*"},
data: {"text": msgData.message[0].cInfo.body},
output: 'output.wav',
success: function() {
console.log("text to voice complete");
var audio = new Audio('output.wav');
audio.play();
}
});
je reçois:
stream.watsonplatform.net/text-to-speech/api/v1/synthesize:1 POST https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize 401 (Processed)
index.html:1 Failed to load https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://52.207.232.200' is therefore not allowed access. The response had HTTP status code 401.
Voir https://stackoverflow.com/questions/43105146/how-to-call-ibm-watson-services-from-javascript/43106268#43106268 – sideshowbarker