I tried to send a POST request to https://speech.googleapis.com/v1/speech:recognize using the JSON and the code fragment below. Somehow google responsed that fail to decoding Base 64 in my request.
{ "config": { "encoding": "LINEAR16", "sampleRateHertz": 16000, "languageCode": "ja-JP", "maxAlternatives": 5, "profanityFilter": false }, "audio": { "content": "ZXCVBNM" }, }
String pcmFilePath = "/storage/emulated/0/Download/voice8K16bitmono.pcm";
File rawFile = new File(pcmFilePath);
byte[] rawData = new byte[(int) rawFile.length()];
DataInputStream input = null;
try {
input = new DataInputStream(new FileInputStream(rawFile));
int readResult = input.read(rawData);
} catch (Exception ex) {
ex.printStackTrace();
}
if (input != null) {
input.close();
};
String base64 = Base64.encodeToString(rawData, Base64.DEFAULT);
String completePostBody = postBody.replace("ZXCVBNM" , base64);
"code": 400, "message": "Invalid value at 'audio.content' (TYPE_BYTES), Base64 decoding failed for \"...
Does anyone have any suggestion ?
ZXCVBNMis invalid (incomplete) base64-encoding (it partially decodes toepòbut is incomplete). Base-64 encodes every three characters of source (binary) data into 4 characters of encoded data. You only have seven characters so is incomplete (and also suspiciously short for any type of audio representation). - TripeHoundZXCVBNMwith what is meant to be your file content (I don't know Android enough to know that your code is reading the file correctly or not). However, the point remains that what Google is receiving isn't valid base-64. Try logging what you're actually sending in the payload to see if it makes sense. (Or, conceivably, Googole isn't expecting base64 (the link is giving 404 for me). - TripeHound