Azure STT is giving error : HttpResponseProxy{HTTP/1.1 400 Bad Request [Content-Type: text/plain; charset=utf-8, Date: Fri, 02 Feb 2024 14:33:46 GMT, Server: Kestrel, Transfer-Encoding: chunked, Strict-Transport-Security: max-age=31536000; includeSubDomains] ResponseEntityProxy{[Content-Type: text/plain; charset=utf-8,Chunked: true]}}. HttpClient httpclient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(env.getProperty("voice.text.api")); BASE64DecodedMultipartFile audio = new BASE64DecodedMultipartFile(Base64.getDecoder().decode(audioReq));
builder.setParameter("language", sourceLang);
URI uri = builder.build();
HttpPost request = new HttpPost(uri);
request.setHeader(CONTENT_TYPE, AUDIO_WAV_TYPE);
request.setHeader("Ocp-Apim-Subscription-Key", env.getProperty("Voice.SubKey1"));
//request.setHeader("Accept","application/json");
request.setEntity(new FileEntity(convert(audio), ContentType.APPLICATION_OCTET_STREAM));
HttpResponse response = null;
try {
response = httpclient.execute(request);
} catch (IOException e) {
throw new RuntimeException(e);
}
The proxy 400 error occurs due to incorrect configuration or invalid data being sent to the Azure Speech-to-Text service.
To fix the error, ensure that the correct endpoint URI for the Azure Speech-to-Text service is used, along with a valid speech key and properly formatted audio data in a .wav file.
Below is the correct endpoint URI:
The following code has been updated with the correct endpoint URI and speech key, enabling it to convert speech to text without any errors.
Code:
Output :
It ran successfully, and the speech was converted to text as shown below.