From 71f54306c775fe8488f7637bd04f86340b762dea Mon Sep 17 00:00:00 2001 From: wh <382379437@qq.com> Date: Fri, 12 Jul 2024 20:37:07 +0800 Subject: [PATCH] fixed --- .../application/index/controller/Test.php | 26 ------ digital_doctor/config/app.php | 2 +- digital_doctor/public/test.php | 88 +++++++++++++++++++ 3 files changed, 89 insertions(+), 27 deletions(-) create mode 100644 digital_doctor/public/test.php diff --git a/digital_doctor/application/index/controller/Test.php b/digital_doctor/application/index/controller/Test.php index 5cca174..888ec17 100644 --- a/digital_doctor/application/index/controller/Test.php +++ b/digital_doctor/application/index/controller/Test.php @@ -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',''); diff --git a/digital_doctor/config/app.php b/digital_doctor/config/app.php index c1b9fa5..4c2c9d5 100644 --- a/digital_doctor/config/app.php +++ b/digital_doctor/config/app.php @@ -199,7 +199,7 @@ return [ //讯飞录音接口 'xunfei_record_config'=>[ 'appid'=>'de02dasd', - 'secretKey'=>'31ce3f96c062958df3c426da4903540c', + 'APIKey'=>'31ce3f96c062958df3c426da4903540c', //'appid'=>'d482af59', //'APIKey'=>'0d20dab630904ad8676d9075375a1914', //'secretKey'=>'Yjg0YTAyNmE5OGUwNDE3YjU4NWE4NmZh', diff --git a/digital_doctor/public/test.php b/digital_doctor/public/test.php new file mode 100644 index 0000000..8819e28 --- /dev/null +++ b/digital_doctor/public/test.php @@ -0,0 +1,88 @@ +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);