0

I got this from the IBM Watson speech to text documents, to send an audio file for processing:

curl -X POST -u <username>:<password>
--header "Content-Type: audio/flac"
--header "Transfer-Encoding: chunked"
--data-binary @<path>0001.flac
"https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?continuous=true"

But how should I build that into PHP cURL? Something like this?

$headr = array();
$headr[] = 'Content-Type: audio/flac';
$headr[] = 'Transfer-Encoding: chunked';
...
$crl = curl_init('https://stream.watsonplatform.net/speech-to-text/api');
curl_setopt($crl, CURLOPT_POST, 1);
curl_setopt($crl, CURLOPT_POSTFIELDS, array("username:password"=>"myuser:mypassword","data-binary"=>"@<path>0001.flac"));
curl_setopt($crl, CURLOPT_HTTPHEADER, $headr);

What about the -x and -u?

Aram Alvarez
  • 536
  • 6
  • 21

1 Answers1

0

-X POST is already set when you did this

curl_setopt($crl, CURLOPT_POST, 1);

as for -u, you can use this, don't include the username:password in your post field array.

curl_setopt($crl, CURLOPT_USERPWD, "yourusername:yourpassword");

for using --data-binary, there is already an existing stackoverflow post on how to accomplish it using php curl: data-binary parameter in cURL

Community
  • 1
  • 1
ebildude123
  • 188
  • 7