To everyone who mask this as a duplicate; please see the other answers you are refering to and the links I have provided here. They content type is audio/wav
and not stream/octet
as mentioned in other answers. Please don't mark questions as duplicates without reading its content
I am trying to send an audio file to a server, so I can get an JSON response back. This is an IBM Service so we have the REST API provided by them. Below is my code in ajax
function recognize()
{
$.ajax
({
type: "POST",
url: "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize",
dataType: 'json',
username: "xxxx",
password: "xxxx",
contentType: "audio/wav",
success: function (data){
alert(JSON.stringify(data));
}
});
}
Below is the IBM example for the REST call I am going to make -
curl -u "{username}":"{password}" \
-H "content-type: audio/wav" \
--data-binary @"/path/to/file.wav" \
"https://stream.watsonplatform.net/speech-to-text/api/v1/sessions/{session_id}/recognize"
The link to the example page and description is - http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/speech-to-text/api/v1/#recognize
My question is, how Can I send the binary file via Ajax? This is actually a phonegap application.
Here is an interesting question; if I send the URI of the file into data:
tag of the REST call it works. If I send the real path it do not. why???