1

I am trying to send a Curl request to Wit.ai speech. I am recording a .wav file on the frontend with recorder.js.

I specified mono channel, since wit.ai only supports mono. I know that php7 doesn't support @ for CURLOPT_POSTFIELDS, so I downgraded my php to 5.6 just to keep it simple.

I used Postman to generate the Curl request.

I also saw this Post which his similar to my issue but I am using a file: How to stream speech to wit.ai speech end point

Note: What I think, I am still lacking wav file parameters, but I am not sure how to get them. I tried properties but there wasn't much info.

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.wit.ai/speech?v=20170307",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_SAFE_UPLOAD => false,
  CURLOPT_POSTFIELDS =>"@uploads/audio1585176568858.wav",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Bearer $token",
    "Content-Type: audio/wav"
  ),
));

$response = curl_exec($curl);
curl_close($curl);
echo $response

The response I get back is this : { "_text": "", "entities": {} }.

I also used a python script with https://pypi.org/project/SpeechRecognition/ lib with same audio .wav file and it worked.

Simon
  • 56
  • 6
  • Please check if curl_error($curl) returns any error – Vishal Mar 27 '20 at 14:45
  • I edited the question to include the current response I am getting and also added before curl_close : if (curl_error($curl)) { echo "error : ". curl_error($curl);}. But no difference in response. – Simon Mar 27 '20 at 15:01
  • 1
    I found the answer with this post : [post-file-curl](https://stackoverflow.com/questions/28643073/post-file-curl-commandline-to-php-curl) ! – Simon Apr 03 '20 at 01:34

0 Answers0