我正在尝试使我的php脚本将curl请求发送到语音文本API。
我在Watson控制台中配置了API,并安装了脚本以发送音频和apikey。
$url = 'https://stream.watsonplatform.net/speech-to-text/api/v1/recognize';
$file = '@files/WhatsApp Audio 2019-01-25 at 12.17.28 (1).flac';
$fields = array(
'file' => $file,
'continuous' => true
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "apikey:KEY");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: audio/flac'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Transfer-Encoding: chunked'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_MAX_SEND_SPEED_LARGE, 40000);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
$executed = curl_exec($ch);
var_dump($executed);
我总是得到这个结果:
string(37)“ {” code“:401,” error“:”未经授权“}”