dongqindan4406 2019-02-03 10:12
浏览 125
已采纳

php cuRL响应“无法转码数据流音频/ flac - > audio / x-float-array” - IBM Watson Speech to text API

I don't know much about how to use cURL.I am trying to convert Speech to Text using IBM Watson API. When I try to convert it without using parameters(Translate English Audio File), I get a response without any error.

But when I add

curl_setopt($ch, CURLOPT_POSTFIELDS, array(
      'model'=>'ja-JP_NarrowbandModel'
))

It returns

{ "code_description": "Bad Request", "code": 400, "error": "unable to 
transcode data stream audio/flac -> audio/x-float-array " }

I am not sure if there is an issue in my Syntax or something else is going wrong there.

I read docs from : https://console.bluemix.net/docs/services/speech-to-text/http.html#http

<?php
$ch = curl_init();
$file = file_get_contents('audio-file.flac');
curl_setopt($ch, CURLOPT_URL, 'https://stream.watsonplatform.net/speech-to-text/api/v1/recognize');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $file);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, 'apikey' . ':' . 'MY_API_HERE');
$headers = array();
$headers[] = 'Content-Type: audio/flac';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'model'=>'ja-JP_NarrowbandModel'
));
$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
print_r($result);
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 二阶矩阵对角化和弹力平衡运动方程问题求解
      • ¥15 multisim10安装后,找不到NI License Manager的程序来安装许可证
      • ¥15 C++银行卡系统 Help!
      • ¥15 JS如何把上面这种数据类型转换成下面这种的
      • ¥15 ubuntu 16.04.2 oss上传文件并显示耗时
      • ¥15 存储过程调用没有进行逻辑计算
      • ¥20 Kali破解WIFI密码中出现这个问题是什么意思
      • ¥15 R语言数据分析的相关问题
      • ¥15 模型导入SP后贴图纹理只有一个,拆了四张UV的,怎么解决?
      • ¥15 检索带order by 非常慢