When I tried to contact the text to speech of Microsoft, I received this error:
Access to XMLHttpRequest at 'https://westeurope.tts.speech.microsoft.com/' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. I'm naturally in Angular and my code is like that:
this.http.post<any>('https://westeurope.api.cognitive.microsoft.com/sts/v1.0/issueToken', null, {headers: new HttpHeaders({'Ocp-Apim-Subscription-Key': '3e17428195894a8f9de3e76ee431ff80'})}).subscribe(
() => {},
(err) => {
console.log(err.error.text);
let body = '<speak version=\'1.0\' xmlns="https://www.w3.org/2001/10/synthesis" xml:lang=\'en-US\'><voice name=\'Microsoft Server Speech Text to Speech Voice (en-US, Jessa24kRUS)\'>Welcome to Microsoft Cognitive Services <break time="100ms" /> Text-to-Speech API.</voice> </speak>';
let headersSpeech = new HttpHeaders({
'Authorization': 'Bearer ' + err.error.text,
'cache-control': 'no-cache',
'X-Microsoft-OutputFormat': 'riff-24khz-16bit-mono-pcm',
'Content-Type': 'application/ssml+xml'
});
this.http.post<any>('https://westeurope.tts.speech.microsoft.com/', body, {headers: headersSpeech}).subscribe(
(resultData) => console.log(resultData)
);
});
Yes, as you can see, Microsoft sent to me an error when I ask a Token but they send me the token inside text error(I don't get it too.) I tried this solution:
let headersSpeech = new HttpHeaders({
'Access-Control-Allow-Origin': 'http://localhost:4200/',
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS',
'Access-Control-Allow-Headers': '*',
'Authorization': 'Bearer ' + err.error.text,
'cache-control': 'no-cache',
'X-Microsoft-OutputFormat': 'riff-24khz-16bit-mono-pcm',
'Content-Type': 'application/ssml+xml'
});
But that's not working. I think the problem is coming from Microsoft but I want to be sure.