3

I am working with Microsoft Cognitive Services and submitting some TTS over the Rest API. If I submit the xml listed below directly to the service via postman, it works fine, if I submit the xml below via my java code I get:

HttpResponseProxy{HTTP/1.1 400 Synthesis failed. StatusCode: FailedPrecondition, Details: SSML parsing error: 8004507A. [Server: openresty/1.15.8.2, Date: Mon, 07 Jun 2021 20:48:40 GMT, Content-Type: text/xml, Transfer-Encoding: chunked, Connection: keep-alive, Strict-Transport-Security: max-age=15724800; includeSubDomains] ResponseEntityProxy{[Content-Type: text/xml,Chunked: true]}}

The java code works flawlessly if I do not inject the SSML

<phoneme alphabet="ipa" ph="təˈmeɪtoʊ"> tomato </phoneme>

The only thing I can think of going wrong is the Entity for the body. With postman this is a raw body. Is there something else I should be doing for the body in java?

HttpPost httpPost = new HttpPost("https://eastus.tts.speech.microsoft.com/cognitiveservices/v1");
httpPost.setEntity(new StringEntity(xml));
httpPost.addHeader("Content-Type", "application/ssml+xml");
httpPost.addHeader("Ocp-Apim-Subscription-Key", key);
httpPost.addHeader("X-Microsoft-OutputFormat", "audio-48khz-192kbitrate-mono-mp3");
org.apache.http.HttpResponse resp = httpclient.execute(httpPost);
<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="en-US"><voice name="en-US-JennyNeural"><mstts:express-as style="assistant"><prosody rate="5%" pitch="13%">
we can totally get a <phoneme alphabet="ipa" ph="təˈmeɪtoʊ"> tomato </phoneme> made for you right now!</prosody></mstts:express-as></voice></speak>
Parzival
  • 2,051
  • 4
  • 14
  • 32
Luke Voelk
  • 41
  • 2
  • 1
    Have you tried specifying the charset with the StringEntity? `new StringEntity(xml, StandardCharsets.UTF_8)` for example? – Jan-Willem Gmelig Meyling Jul 22 '21 at 15:49
  • 1
    Or alternatively, `HttpEntity entity = new ByteArrayEntity(xml.getBytes("UTF-8")); httpPost.setEntity(entity);` – jccampanero Jul 22 '21 at 18:52
  • Tyvm this solved the problem. Now how do I award a bounty for a comment? – lvoelk Jul 23 '21 at 03:45
  • Hi @lvoelk. That is great, I am happy to hear that the issue is solved. You cannot award the bounty for a comment. You can place your own answer if you wish, the important thing is that the problem is solved. If you want me or Jan to write and answer, please, indicate which comment best fits your needs, and we will write an answer if necessary. – jccampanero Jul 23 '21 at 15:49

0 Answers0