我通过"https://speech.googleapis.com/v1/speech:recognize?key=<my key>"
以下方式向 GCS 发送音频:
byte[] audioBytes = g_NPCAudioListener.GetAudioClipMonoData16(88200);
string jsonData = "{" +
"\"config\": {" +
"\"encoding\": \"LINEAR16\"," +
"\"sampleRateHertz\": 48000," +
"\"languageCode\": \"en-US\"" +
"}," +
"\"audio\": {" +
"\"content\" : \"" + Convert.ToBase64String(audioBytes) + "\"" +
"}" +
"}";
byte[] postData = System.Text.Encoding.UTF8.GetBytes(jsonData);
g_NPCController.Debug("Sending to google: " + jsonData);
using (WWW req = new WWW(g_Google_Speech_URL, postData, g_JSONHeaders)) {
yield return req;
if (req.error == null) {
g_NPCController.Debug(req.text.Replace("\n", "").Replace(" ", ""));
} else {
string msg = Convert.ToString(req.bytes);
g_NPCController.Debug("Google Speech Error: " + req.error + "\n - error: " + req.text);
}
}
一切都符合规范,但是,我一直得到一个空主体的错误标志。
在处理主要的 JSON impl 时,我得到了“无效参数”等......但现在我正在流式传输 88200 个 16 位未压缩音频字节块,我不断收到一个错误,没有附加文本 - 甚至没有一个代码。有没有人遇到过类似的情况?
如果相关,我从 Unity 中的 AudioClip 获取音频,然后将 32 位 float[] 转换为 byte[originalAudio.Length * sizeof(float)],然后根据需要转换为 base64。
谢谢。