Why
There is no sample code with PHP on official document
Environment
PHP 7.1.8
Zend Engine v3.1.0
Code
<?php
$language = 'en-US'
$url = 'https://westus.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language='.$language;
$curl = curl_init();
$header = [
'Ocp-Apim-Subscription-Key: {your key}',
'Content-Type: audio/wav; codec=audio/pcm; samplerate=16000',
'Accept: application/json'
];
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, file_get_contents('test_audio.wav'));
$response = curl_exec($curl);
curl_close($curl);
/* for debug
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
$info = curl_getinfo($curl);
var_dump($info);
*/
var_dump($response);