Microsoft TTS and Apache HttpRequest

230 Views Asked by At

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>
0

There are 0 best solutions below