我尝试使用 JSON 和下面的代码片段向https://speech.googleapis.com/v1/speech:recognize发送 POST 请求。谷歌以某种方式回应未能在我的请求中解码 Base 64。
{“配置”:{“编码”:“LINEAR16”,“sampleRateHertz”:16000,“语言代码”:“ja-JP”,“maxAlternatives”:5,“profanityFilter”:假},“音频”:{“内容": "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": "'audio.content' (TYPE_BYTES) 的值无效,\" 的 Base64 解码失败...
有人有什么建议吗?