'true' //'verify_ssl' => false, //... ]; // 这里的$app_id、$secret_key是在开放平台控制台获得 $client = new LfasrClient($appId, $secretKey, $lfasrConfig); $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); //// 将音频数据转换为文件,以便传递给iFLYTEK SDK //$tempFile = tempnam(sys_get_temp_dir(), 'audio'); //Tools::log_to_write_txt(['tempFile:',$tempFile]); //file_put_contents($tempFile, $audioData); // //Tools::log_to_write_txt(['$xunfei_record_config'=>$xunfei_record_config]); ////$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); //Tools::log_to_write_txt(['进度'=>$progress]); // //if ($progress['ok'] !== 0) { // //echo "获取任务进度失败\n"; // $res_json = BaseWssApi::json_wss('error','获取任务进度失败',$progress); // 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','获取任务进度失败',$progress); // 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); // return; //} } function revert_test($client_id,$audioData){ $xunfei_record_config = config('xunfei_record_config'); $appId = $xunfei_record_config['appid']; $secretKey = $xunfei_record_config['APIKey']; dump($xunfei_record_config); $client = new LfasrClient($appId, $secretKey); echo "开始上传音频...\n"; $filePath = Tools::get_root_path().'public/iseTest.mp3'; $taskId = $client->combineUpload($filePath); echo "音频上传成功,task_id: $taskId\n"; do { $progress = json_decode($client->getProgress($taskId)->getBody()->getContents(), true); dump($progress);die; if ($progress['ok'] !== 0) { echo "获取任务进度失败\n"; exit; } if ($progress['err_no'] !== 0) { echo "获取任务进度失败,错误码:" . $progress['err_no'] . "\n"; exit; } $data = json_decode($progress['data'], true); if ($data['status'] == 9) { echo "音频转写成功,开始获取结果...\n"; break; } else { echo "音频转写中...\n"; } sleep(5); } while (true); $result = $client->getResult($taskId)->getBody()->getContents(); echo $result; return $result; } }