根据https://cloud.google.com/speech/reference/rest/v1beta1/speech/asyncrecognize#authorization,我正在尝试将包含以下信息的发布请求发送到https://speech.googleapis.com/v1beta1 /speech:asyncrecognize在正文中:
{
"config": {
"encoding": 'FLAC',
"sampleRate": 16000,
},
"audio": {
"content": <a base64-encoded string representing an audio file>,
},
}
我不知道如何在正文中设置这些参数。我们有 json 数据以及要放入正文的音频文件的二进制内容。这是我的代码:
string mServerUrl = @"https://speech.googleapis.com/v1beta1/speech:asyncrecognize";
MultipartFormDataContent content = new MultipartFormDataContent();
content.Add(new StringContent("config"), "\"encoding\":\"FLAC\",\"sampleRate\":16000");
content.Add(CreateFileContent("audio.flac"));
HttpClient mHttpClient = new HttpClient();
HttpResponseMessage mResponse = null;
mResponse = await mHttpClient.PostAsync(mServerUrl, content);
string responseBodyAsText = await mResponse.Content.ReadAsStringAsync();