javascript - 对于像 https ://watson-speech. mybluemix.net/microphone-streaming.html 这样的简单语音到文本应用程序,是否有一些 libcurl 脚本?

标签 javascript php libcurl ibm-watson speech-to-text

我在 IBM 上做了一个精简计划,想将麦克风中的语音转录到一个容器中,并在我的服务器上创建一个音频文件。 (如示例页面 here
为此,我使用 PHP 的 libcurl。

如何使用通过 JSON 片段获得的 API key 和其他变量?

"apikey": "<api-key>",
"iam_apikey_description": "<description>",
"iam_apikey_name": "<apikey-name>",
"iam_role_crn": "<role-crn>",
"iam_serviceid_crn": "<serviceid_crn>",
"url": "https://gateway-lon.watsonplatform.net/speech-to-text/api"

我试过这个:
$json      = file_get_contents('./srv/lb/watson/watson.json');
$json_data = json_decode($json,true);

$file      = fopen('./srv/data/0001.flac', 'r');
$size      = filesize('./srv/data/0001.flac');
$filedata  = fread($file,$size);
$headers   = array(
"Content-Type: audio/flac",
"Transfer-Encoding: chunked"
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $json_data['url']);
curl_setopt($ch, CURLOPT_USERPWD, "apikey:".$json_data['apikey']);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $filedata);
curl_setopt($ch, CURLOPT_INFILE, $file);
curl_setopt($ch, CURLOPT_INFILESIZE, $size);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$executed = curl_exec($ch);
curl_close($ch);
var_dump($executed);

但我得到了:

string(153) "{ "code": 404, "code_description": "Not Found", "error": "No route found for http://gateway-lon.watsonplatform.net/speech-to-text/api (usher)" }"

最佳答案

React.createElement("div", {
类名:“购物 list ”
}, React.createElement("h1", null, "购物 list ", props.name), React.createElement("ul", null, React.createElement("li", null, "Instagram"), React. createElement("li", null, "WhatsApp"), React.createElement("li", null, "Oculus")));
感谢您为 Stack Overflow 提供答案!
项目 v2 开始

关于javascript - 对于像 https ://watson-speech. mybluemix.net/microphone-streaming.html 这样的简单语音到文本应用程序,是否有一些 libcurl 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57373455/

相关文章:

php - 在 CodeIgniter/PHP 中从数据库中删除超过 x 天的项目

php - 数组数据计算

c - 将 CURL 使用的普通套接字转换为 C 中的 SSL 套接字

PHP - curl_exec 挂起

PHP Curl 进度条(回调返回百分比)

javascript - 为什么我的 gulp 任务不关注变化?

javascript - express.Createserver() 不工作

php - Yii2:回显变量两次给出错误的结果

javascript - Socket.io broadcast.to 不工作但 broadcast.emit 不工作

javascript - 使用 Jasmine 监视 document.createElement 从 Angular 模拟中抛出错误