gpt4 book ai didi

android - Google Speech API 的 Base64 解码失败

转载 作者:搜寻专家 更新时间:2023-11-01 08:27:17 26 4
gpt4 key购买 nike

我试图向 https://speech.googleapis.com/v1/speech:recognize 发送 POST 请求使用 JSON 和下面的代码 fragment 。谷歌以某种方式回应说未能在我的请求中解码 Base 64。

{ “配置”:{ “编码”:“LINEAR16”, “采样率赫兹”:16000, "languageCode": "ja-JP", “最大选择”:5, “亵渎过滤器”:假 }, “声音的”: { “内容”:“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);

“代码”:400, "message": "'audio.content' (TYPE_BYTES) 的值无效,Base64 解码失败\"...

有人有什么建议吗?

最佳答案

我设法从 Google Speech API 获得了结果。

据记载,Base 64 编码不应该换行链接:https://cloud.google.com/speech/docs/base64-encoding

Base64.DEFAULT 更改为 Base64.NO_WRAP 在我的案例中有效。另外 pcm 文件应该是 LSB

关于android - Google Speech API 的 Base64 解码失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43606167/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com