In order to send an audio wav file to the WebAPI controller for Microsoft Bing Speech API calls, the following steps have been taken:
The audio was recorded and converted to base64 data using JavaScript on the client side.
An AJAX call was made to invoke the WebAPI controller and send the base64 audio data as well.
Within the WebAPI controller, the base64 data was converted to bytes and sent to the RESTful API provided by Microsoft.
If you can provide guidance on how to correctly execute these steps, it would be greatly appreciated.
Here is the AJAX call:
$.ajax({
url: 'http://localhost:49818/api/voice',
type: 'POST',
data: base64Data,
dataType: 'json',
contentType: "application/json",
success: function (data) {
alert(data);
}
});
And here is the WebAPI controller method:
string b64 = Request.Content.ReadAsStringAsync().Result;
var client = new HttpClient();
byte[] toBytes1 = Encoding.ASCII.GetBytes(b64);
var uri = "https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles/a1cb4a95-9e09-4f54-982b-09632aee7458/enroll?shortAudio=true";
HttpResponseMessage response;
byte[] toBytes = Encoding.ASCII.GetBytes(b64);
using (var content = new ByteArrayContent(toBytes)) {
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
//content.Headers.ContentType = new MediaTypeHeaderValue("audio/wav");
response = await client.PostAsync(uri, content);
}