From e249bf6cc7810e982f5d25d4f615c986c0fc6b03 Mon Sep 17 00:00:00 2001 From: wh <382379437@qq.com> Date: Fri, 12 Jul 2024 17:50:19 +0800 Subject: [PATCH] fixed --- .../api/logic/AudioRevertLogic.php | 72 +++++++++++++++++++ .../application/index/logic/events/Events.php | 51 +------------ 2 files changed, 75 insertions(+), 48 deletions(-) create mode 100644 digital_doctor/application/api/logic/AudioRevertLogic.php diff --git a/digital_doctor/application/api/logic/AudioRevertLogic.php b/digital_doctor/application/api/logic/AudioRevertLogic.php new file mode 100644 index 0000000..82284a0 --- /dev/null +++ b/digital_doctor/application/api/logic/AudioRevertLogic.php @@ -0,0 +1,72 @@ +combineUpload(__DIR__ . '/../resource/lfasrTest.wav'); + $taskId = $client->combineUpload($tempFile); + Tools::log_to_write_txt(['音频上传成功']); + //echo "音频上传成功,task_id: $taskId\n"; + //do { + $progress = json_decode($client->getProgress($taskId)->getBody()->getContents(), true); + + if ($progress['ok'] !== 0) { + //echo "获取任务进度失败\n"; + $res_json = BaseWssApi::json_wss('error','获取任务进度失败'); + Tools::log_to_write_txt($res_json); + Gateway::sendToClient($client_id, $res_json); + return; + } + + if ($progress['err_no'] !== 0) { + $res_json = BaseWssApi::json_wss('error','获取任务进度失败'); + Tools::log_to_write_txt($res_json); + Gateway::sendToClient($client_id, $res_json); + return; + } + $data = json_decode($progress['data'], true); + + if ($data['status'] == 9) { + + $result = $client->getResult($taskId)->getBody()->getContents(); + $res_json = BaseWssApi::json_wss('wss_revert_audio','音频转写成功开始获取结果',$result); + Tools::log_to_write_txt($res_json); + Gateway::sendToClient($client_id, $res_json); + return; + } else { + $res_json = BaseWssApi::json_wss('error','持续转写中,错误:',$data); + Tools::log_to_write_txt($res_json); + Gateway::sendToClient($client_id, $res_json); + } + + } +} \ No newline at end of file diff --git a/digital_doctor/application/index/logic/events/Events.php b/digital_doctor/application/index/logic/events/Events.php index 02e087a..334c980 100644 --- a/digital_doctor/application/index/logic/events/Events.php +++ b/digital_doctor/application/index/logic/events/Events.php @@ -3,6 +3,7 @@ namespace app\index\logic\events; use app\api\controller\BaseWssApi; +use app\api\logic\AudioRevertLogic; use app\api\logic\PartnerOfflineLogic; use app\api\logic\UserLogic; use app\api\logic\WssMessageLogic; @@ -199,7 +200,7 @@ class Events extends \think\worker\Events //$client = new VmsClient('YOUR_APPID', 'YOUR_SECRET_KEY'); // 音频数据接收处理 - $audioData = $data; + //$audioData = $data; //// 将音频数据转换为文件,以便传递给iFLYTEK SDK //$tempFile = tempnam(sys_get_temp_dir(), 'audio'); @@ -242,54 +243,8 @@ class Events extends \think\worker\Events //// 清理临时文件 //unlink($tempFile); - $xunfei_record_config = config('xunfei_record_config'); - $appId = $xunfei_record_config['appid']; - $secretKey = $xunfei_record_config['secretKey']; - // 将音频数据转换为文件,以便传递给iFLYTEK SDK - $tempFile = tempnam(sys_get_temp_dir(), 'audio'); - Tools::log_to_write_txt(['tempFile:',$tempFile]); - file_put_contents($tempFile, $audioData); - - //$appId = '5ca1e5**';// 此行代码需要更换为用户自己的appid - //$secretKey = '4e41a9b93846815****************';// 此行代码需要更换为用户自己的secretKey - $client = new LfasrClient($appId, $secretKey); - Tools::log_to_write_txt(['开始上传音频']); - //echo "开始上传音频...\n"; - //$taskId = $client->combineUpload(__DIR__ . '/../resource/lfasrTest.wav'); - $taskId = $client->combineUpload($tempFile); - Tools::log_to_write_txt(['音频上传成功']); - //echo "音频上传成功,task_id: $taskId\n"; - //do { - $progress = json_decode($client->getProgress($taskId)->getBody()->getContents(), true); + (new AudioRevertLogic())->revert($client_id,$data); - if ($progress['ok'] !== 0) { - //echo "获取任务进度失败\n"; - $res_json = BaseWssApi::json_wss('error','获取任务进度失败'); - Tools::log_to_write_txt($res_json); - Gateway::sendToClient($client_id, $res_json); - return; - } - - if ($progress['err_no'] !== 0) { - $res_json = BaseWssApi::json_wss('error','获取任务进度失败'); - Tools::log_to_write_txt($res_json); - Gateway::sendToClient($client_id, $res_json); - return; - } - $data = json_decode($progress['data'], true); - - if ($data['status'] == 9) { - - $result = $client->getResult($taskId)->getBody()->getContents(); - $res_json = BaseWssApi::json_wss('wss_revert_audio','音频转写成功开始获取结果',$result); - Tools::log_to_write_txt($res_json); - Gateway::sendToClient($client_id, $res_json); - return; - } else { - $res_json = BaseWssApi::json_wss('error','持续转写中,错误:',$data); - Tools::log_to_write_txt($res_json); - Gateway::sendToClient($client_id, $res_json); - } //sleep(5); //} while (true);