fixed
This commit is contained in:
@@ -28,34 +28,8 @@ class Test extends BasePublicController
|
||||
{
|
||||
function test()
|
||||
{
|
||||
$xunfei_record_config = config('xunfei_record_config');
|
||||
$appId = $xunfei_record_config['appid'];
|
||||
$secretKey = $xunfei_record_config['secretKey'];
|
||||
|
||||
// 设置转写参数
|
||||
$lfasrConfig = [
|
||||
'hasParticiple' => 'true'
|
||||
//...
|
||||
];
|
||||
|
||||
dump($xunfei_record_config);
|
||||
// 这里的$app_id、$secret_key是在开放平台控制台获得
|
||||
$client = new LfasrClient($appId, $secretKey, $lfasrConfig);
|
||||
|
||||
dump($client);
|
||||
$filePath = Tools::get_root_path().'public/iseTest.mp3';
|
||||
dump($filePath);
|
||||
// $filePath为待转写的本地文件路径,返回taskId作为后续查询进度、获取结果操作的参数
|
||||
$taskId = $client->combineUpload($filePath);
|
||||
dump($taskId);
|
||||
|
||||
// 查询进度,json格式
|
||||
$progress = $client->getProgress($taskId)->getBody()->getContents();
|
||||
dump($progress);
|
||||
|
||||
// 获取结果,json格式
|
||||
$result = $client->getResult($taskId)->getBody()->getContents();
|
||||
dump($result);
|
||||
|
||||
|
||||
//(new AudioRevertLogic())->revert('asdsssssssssss','');
|
||||
|
||||
@@ -199,7 +199,7 @@ return [
|
||||
//讯飞录音接口
|
||||
'xunfei_record_config'=>[
|
||||
'appid'=>'de02dasd',
|
||||
'secretKey'=>'31ce3f96c062958df3c426da4903540c',
|
||||
'APIKey'=>'31ce3f96c062958df3c426da4903540c',
|
||||
//'appid'=>'d482af59',
|
||||
//'APIKey'=>'0d20dab630904ad8676d9075375a1914',
|
||||
//'secretKey'=>'Yjg0YTAyNmE5OGUwNDE3YjU4NWE4NmZh',
|
||||
|
||||
88
digital_doctor/public/test.php
Normal file
88
digital_doctor/public/test.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
//use Xfyun\XfyunSDK;
|
||||
|
||||
class Client
|
||||
{
|
||||
private $ws;
|
||||
private $end_tag = "{\"end\": true}";
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$app_id = 'de02dasd';
|
||||
$api_key = '31ce3f96c062958df3c426da4903540c';
|
||||
$base_url = "ws://rtasr.xfyun.cn/v1/ws";
|
||||
$ts = strval(time());
|
||||
$tt = ($app_id . $ts);
|
||||
$md5 = hash('md5', $tt, true);
|
||||
$baseString = bin2hex($md5);
|
||||
$apiKey = $api_key;
|
||||
$signa = hash_hmac('sha1', $baseString, $apiKey, true);
|
||||
$signa = base64_encode($signa);
|
||||
$signa = urlencode($signa);
|
||||
|
||||
$this->ws = new WebSocket\Client($base_url . "?appid=" . $app_id . "&ts=" . $ts . "&signa=" . $signa);
|
||||
}
|
||||
|
||||
public function send($file_path)
|
||||
{
|
||||
$file_object = fopen($file_path, 'rb');
|
||||
try {
|
||||
$index = 1;
|
||||
while (!feof($file_object)) {
|
||||
$chunk = fread($file_object, 1280);
|
||||
if (!$chunk) {
|
||||
break;
|
||||
}
|
||||
$this->ws->send($chunk);
|
||||
|
||||
$index += 1;
|
||||
sleep(0.04);
|
||||
}
|
||||
} finally {
|
||||
fclose($file_object);
|
||||
}
|
||||
|
||||
$this->ws->send($this->end_tag);
|
||||
echo "send end tag success";
|
||||
}
|
||||
|
||||
public function recv()
|
||||
{
|
||||
while ($this->ws->isConnected()) {
|
||||
$result = $this->ws->receive();
|
||||
if (strlen($result) == 0) {
|
||||
echo "receive result end";
|
||||
break;
|
||||
}
|
||||
$result_dict = json_decode($result, true);
|
||||
// 解析结果
|
||||
if ($result_dict["action"] == "started") {
|
||||
echo "handshake success, result: " . $result;
|
||||
}
|
||||
|
||||
if ($result_dict["action"] == "result") {
|
||||
$result_1 = $result_dict;
|
||||
echo "rtasr result: " . $result_1["data"];
|
||||
}
|
||||
|
||||
if ($result_dict["action"] == "error") {
|
||||
echo "rtasr error: " . $result;
|
||||
$this->ws->close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
$this->ws->close();
|
||||
echo "connection closed";
|
||||
}
|
||||
}
|
||||
|
||||
$app_id = "";
|
||||
$api_key = "";
|
||||
$file_path = "/www/wwwroot/digital_doctor/digital_doctor/public/iseTest.mp3";
|
||||
|
||||
$client = new Client();
|
||||
$client->send($file_path);
|
||||
Reference in New Issue
Block a user