From 7bb28d88b55fc96b26911672702ab3edf63c6065 Mon Sep 17 00:00:00 2001 From: wh <382379437@qq.com> Date: Fri, 12 Jul 2024 14:36:09 +0800 Subject: [PATCH] fixed --- .../application/index/logic/events/Events.php | 112 +++++++++--------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/digital_doctor/application/index/logic/events/Events.php b/digital_doctor/application/index/logic/events/Events.php index e135641..c5ad584 100644 --- a/digital_doctor/application/index/logic/events/Events.php +++ b/digital_doctor/application/index/logic/events/Events.php @@ -183,65 +183,65 @@ class Events extends \think\worker\Events //$res = Tools::set_ok('ok',['client_id'=>$client_id,'msg'=>'你发来的消息我接收到了:',$client_id=>$data]); //Gateway::sendToClient($client_id,json_encode($res,JSON_UNESCAPED_UNICODE)); - if(empty($data)){ - $json = BaseWssApi::json_wss('onMessage','消息为空',['client_id'=>$client_id,'data'=>$data]); - - Gateway::sendToClient($client_id, $json); - return ; - } - //解析消息 - - //解析action - - //调用业务逻辑&响应处理结果 - //(new WssMessageLogic())->domsg($client_id,$data); - - //$client = new VmsClient('YOUR_APPID', 'YOUR_SECRET_KEY'); - - // 音频数据接收处理 - $audioData = $data; - - // 将音频数据转换为文件,以便传递给iFLYTEK SDK - $tempFile = tempnam(sys_get_temp_dir(), 'audio'); - file_put_contents($tempFile, $audioData); - // 设置请求参数 - //$params = [ + //if(empty($data)){ + // $json = BaseWssApi::json_wss('onMessage','消息为空',['client_id'=>$client_id,'data'=>$data]); + // + // Gateway::sendToClient($client_id, $json); + // return ; + //} + ////解析消息 + // + ////解析action + // + ////调用业务逻辑&响应处理结果 + ////(new WssMessageLogic())->domsg($client_id,$data); + // + ////$client = new VmsClient('YOUR_APPID', 'YOUR_SECRET_KEY'); + // + //// 音频数据接收处理 + //$audioData = $data; + // + //// 将音频数据转换为文件,以便传递给iFLYTEK SDK + //$tempFile = tempnam(sys_get_temp_dir(), 'audio'); + //file_put_contents($tempFile, $audioData); + //// 设置请求参数 + ////$params = [ + //// 'sample_rate' => 16000, // 采样率 + //// 'language' => 'zh_cn', // 语言 + ////]; + //// 设置转写参数 + //$lfasrConfig = [ + // 'hasParticiple' => 'true', // 'sample_rate' => 16000, // 采样率 // 'language' => 'zh_cn', // 语言 + // //... //]; - // 设置转写参数 - $lfasrConfig = [ - 'hasParticiple' => 'true', - 'sample_rate' => 16000, // 采样率 - 'language' => 'zh_cn', // 语言 - //... - ]; - $xunfei_record_config = config('xunfei_record_config'); - $app_id = $xunfei_record_config['appid']; - $secret_key = $xunfei_record_config['secretKey']; - - - $filePath = $tempFile;//'/Users/wh/Desktop/test.wav'; - // 这里的$app_id、$secret_key是在开放平台控制台获得 - $client = new LfasrClient($app_id, $secret_key, $lfasrConfig); - - // $filePath为待转写的本地文件路径,返回taskId作为后续查询进度、获取结果操作的参数 - $taskId = $client->combineUpload($filePath); - - // 查询进度,json格式 - $progress = $client->getProgress($taskId)->getBody()->getContents(); - Tools::log_to_write_txt(['查询进度,json格式:'=>$progress]); - // 获取结果,json格式 - $result = $client->getResult($taskId)->getBody()->getContents(); - Tools::log_to_write_txt(['获取结果,json格式:'=>$result]); - // 清理临时文件 - unlink($tempFile); - - - - - // 处理翻译结果,例如保存到数据库或返回给前端 - Gateway::sendToClient($client_id, $result); + //$xunfei_record_config = config('xunfei_record_config'); + //$app_id = $xunfei_record_config['appid']; + //$secret_key = $xunfei_record_config['secretKey']; + // + // + //$filePath = $tempFile;//'/Users/wh/Desktop/test.wav'; + //// 这里的$app_id、$secret_key是在开放平台控制台获得 + //$client = new LfasrClient($app_id, $secret_key, $lfasrConfig); + // + //// $filePath为待转写的本地文件路径,返回taskId作为后续查询进度、获取结果操作的参数 + //$taskId = $client->combineUpload($filePath); + // + //// 查询进度,json格式 + //$progress = $client->getProgress($taskId)->getBody()->getContents(); + //Tools::log_to_write_txt(['查询进度,json格式:'=>$progress]); + //// 获取结果,json格式 + //$result = $client->getResult($taskId)->getBody()->getContents(); + //Tools::log_to_write_txt(['获取结果,json格式:'=>$result]); + //// 清理临时文件 + //unlink($tempFile); + // + // + // + // + //// 处理翻译结果,例如保存到数据库或返回给前端 + //Gateway::sendToClient($client_id, $result); }