簡體   English   中英

對於像https://watson-speech.mybluemix.net/microphone-streaming.html這樣的簡單語音轉文本應用程序,是否有一些libcurl腳本?

[英]Is there a bit of libcurl script for a simple speech-to-text application like this https://watson-speech.mybluemix.net/microphone-streaming.html?

我在IBM上制定了一個精簡計划,希望將語音從麥克風轉錄到容器中,並在服務器上創建音頻文件。 (如此處示例頁面所示為此,我使用了PHP的libcurl。

如何使用通過JSON代碼段獲得的API密鑰和其他變量?

"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)“ {”代碼“:404,” code_description“:”未找到“,”錯誤“:”未找到http://gateway-lon.watsonplatform.net/speech-to-text/api的路由(招待員)” }”

React.createElement(“ div”,{className:“購物清單”},React.createElement(“ h1”,null,“購物清單”,props.name),React.createElement(“ ul”,null,React .createElement(“ li”,null,“ Instagram”),React.createElement(“ li”,null,“ WhatsApp”),React.createElement(“ li”,null,“ Oculus”))))); 感謝您為Stack Overflow提供答案! 項目v2已啟動

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM