H
H
habra_desert2015-10-03 23:25:46
PHP
habra_desert, 2015-10-03 23:25:46

PHP CURL + Yandex Speechkit - how to make it work?

The actual problem is with the Content-Type headers ;
if I put it, because Yandex asks for Content-Type: audio/x-wav, then in the answer I get
Unknown Content-Type or multipart/form-data expected!
if Content-Type: multipart/form-data then response
Record is present, but 'Content-Type' param not specified!
Help me figure out
the code itself:

$url = "https://asr.yandex.net/asr_xml?uuid=".$uuid."&key=".$key."&topic=".$topic."&lang=".$lang;
$file['audio'] = '@c:/xampp/htdocs/speechkit/test.wav;

$headers = array("Transfer-Encoding: chunked", "Content-Type: audio/x-wav");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 
curl_setopt($ch, CURLOPT_POST, true) ;        
curl_setopt($ch, CURLOPT_POSTFIELDS, $file) ;
  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//проверка SSL- сертификата
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 

// отсылаем запрос
$response = curl_exec($ch);
/выводим
echo $response;

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
LAV45, 2017-12-26
@LAV45

Here is a working code example. A normal GET request is sent.

/**
 * @see https://tech.yandex.ru/speechkit/cloud/doc/guide/concepts/tts-http-request-docpage/
 */
$apiUrl = 'https://tts.voicetech.yandex.net/generate';
$options = [
    'key' => '******',
    'speaker' => 'oksana',
    'format' => 'mp3',
    'lang' => 'ru-RU',
    'speed' => 1.2
];

$options['text'] = $text;

$url = $apiUrl . '?' . http_build_query($options);
$data = file_get_contents($url);

file_put_contents('audio.' . $options['format'], $data);

M
Maxim Khodyrev, 2012-01-17
@maximkou

it seemed to me that there is php for such things ...

A
Alexander Zelenin, 2012-01-18
@zelenin

you created the question twice, wrote back to you in the first version, I will repeat here, if the discussion has already begun here, did
you invent the iframe or include?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question