I am using Google Speech REST API to convert speech to text, I am getting blank response. Here is my json which I was passing in Http Post Request:-
This is my code to get JSON:
File file = new File(mOutputFile.getAbsolutePath());
byte[] bytes = new byte[0];
try {
bytes = loadFile(file);
} catch (IOException e) {
e.printStackTrace();
}
byte[] encoded = Base64.encodeBase64(bytes);
String encodedString = new String(encoded);
JSONObject config = new JSONObject();
config.put("encoding", "FLAC");
config.put("sampleRateHertz", 16000);
config.put("languageCode", "en-US");
config.put("enableWordTimeOffsets", false);
JSONObject audio = new JSONObject();
audio.put("content", "" + encodedString);
JSONObject jsonObject = new JSONObject();
jsonObject.put("config", config);
jsonObject.put("audio", audio);
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost("https://speech.googleapis.com/v1/speech:recognize?key=GOOGLE_API_KEY");
post.setHeader("content-type", "application/json; charset=UTF-8");
StringEntity entity = new StringEntity(jsonObject.toString());
post.setEntity(entity);
HttpResponse resp = httpClient.execute(post);
s = EntityUtils.toString(resp.getEntity());
Log.e("ExecuteTask Response", "--------------" + s);
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception exception) {
exception.printStackTrace();
}