Как с помощью php реализовать загрузку файла для YandexSpeechKit частями?
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
$new = str_split(file_get_contents(realpath("$file_name")), 1000);
$data = "";
foreach ($new as $now){
$data .= dechex(strlen($now))."\r\n".$now."\r\n";
}
$data .= "0\r\n\r\n";
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: audio/x-pcm;bit=16;rate=16000', "Transfer-Encoding: chunked"));
curl_setopt($curl, CURLOPT_VERBOSE, true);
$response = curl_exec($curl);
попытался сделать это кодом выше, но не получилось.
В итоге пришлось отказаться от curl, и использовать file_get_contents
$new = str_split(file_get_contents(realpath("$file_name")), 2000);
$data = "";
foreach ($new as $now){
$data .= dechex(strlen($now))."\r\n";
$data .= $now;
$data .= "\r\n";
}
$data .= "0\r\n\r\n";
$aHTTP = array(
'http' =>
array(
'method' => 'POST',
'header' => ["Content-Type: audio/x-pcm;bit=16;rate=16000", "Transfer-Encoding: chunked"],
'content' => $data,
'protocol_version' => 1.1,
'follow_location' => 1
)
);
$context = stream_context_create($aHTTP);
$response = file_get_contents($url, false, $context);
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости