This commit is contained in:
2024-07-12 17:27:59 +08:00
parent 7bedad408a
commit 951ce07821
4 changed files with 138 additions and 89 deletions

View File

@@ -0,0 +1,22 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/7/12} {17:01}
*/
namespace app\api\controller;
/**
* 健康洞察
*
* Class HealthInsights
* @package app\api\controller
*/
class HealthInsights
{
}

View File

@@ -1,30 +0,0 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/7/11} {16:32}
*/
namespace app\api\controller;
use think\Db;
/**
* 听译-诊断报告
* Class Medicalreportty
* @package app\api\controller
*/
class Medicalreportty
{
/**
* desc查询报告
* authorwh
*/
function getReport(){
//Db::table('fa_ty_medical_report')
// ->where('')
}
}

View File

@@ -23,30 +23,18 @@ class Reportty
{
/**
* desc获取报告
* desc听译-获取听诊报告
*
* curl --location --request POST 'https://serverfastgpt.excn.top/api/v1/chat/completions' \
--header 'Authorization: Bearer fastgpt-e5wq9u6phvyfq4znrXfOuTHKHQHGjpcVBYay602ai5zv4HeOJRMDwT3ptm6' \
--header 'Content-Type: application/json' \
--data-raw '{
"stream": false,
"detail": false,
"messages": [
{
"content": "医患对话内容",
"role": "user"
}
]
}'
* api/Reportty/getReport
*
* authorwh
* @return mixed
*/
function getReport(){
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
header('Connection: keep-alive');
header('X-Accel-Buffering: no');
function createReport(){
//header('Content-Type: text/event-stream');
//header('Cache-Control: no-cache');
//header('Connection: keep-alive');
//header('X-Accel-Buffering: no');
$config = config('ai_report_config');
$question = '';//input('question','');
@@ -54,7 +42,7 @@ class Reportty
$chatobj = new ChatGPT();
$chatobj->url = $config['base_url'];
$chatobj->model = '';
$chatobj->apiKey = $config['APIKey'];
$chatobj->apiKey = $config['APIKey'].':'.$config['APISecret'];
$answer_json_arr = [];
@@ -82,4 +70,26 @@ class Reportty
$chatobj->chat($question,$config,$answer_json_arr);
}
/**
* desc查询报告
*
* api/Reportty/getReport
* 参数username
*
* authorwh
*/
function getReport(){
}
/**
* 修改报告
* api/Reportty/editReport
* 参数username
*/
function editReport(){
}
}

View File

@@ -184,7 +184,7 @@ class Events extends \think\worker\Events
//Gateway::sendToClient($client_id,json_encode($res,JSON_UNESCAPED_UNICODE));
if(empty($data)){
$json = BaseWssApi::json_wss('error','消息为空',['client_id'=>$client_id,'data'=>$data]);
$json = BaseWssApi::json_wss('error','消息为空');
Gateway::sendToClient($client_id, $json);
return ;
@@ -201,53 +201,100 @@ class Events extends \think\worker\Events
// 音频数据接收处理
$audioData = $data;
//// 将音频数据转换为文件以便传递给iFLYTEK SDK
//$tempFile = tempnam(sys_get_temp_dir(), 'audio');
//Tools::log_to_write_txt(['tempFile:',$tempFile]);
//file_put_contents($tempFile, $audioData);
//
//// 设置转写参数
//$lfasrConfig = [
// 'hasParticiple' => 'true',
// //'sample_rate' => 16000, // 采样率
// 'language' => 'zh_cn', // 语言
// //...
//];
//$xunfei_record_config = config('xunfei_record_config');
//$appId = $xunfei_record_config['appid'];
//$secretKey = $xunfei_record_config['secretKey'];
//
//Tools::log_to_write_txt(['app_id:',$appId]);
//Tools::log_to_write_txt(['secret_key:',$secretKey]);
//
//$filePath = $tempFile;//'/Users/wh/Desktop/test.wav';
//// 这里的$appId、$secretKey是在开放平台控制台获得
//$client = new LfasrClient($appId, $secretKey, $lfasrConfig);
//Tools::log_to_write_txt(['初始化$client:'=>$client]);
//if(empty($client)){
// Tools::log_to_write_txt(['初始化client初始化失败:$client为空。'=>$client]);
// return;
//}
//
//// $filePath为待转写的本地文件路径返回taskId作为后续查询进度、获取结果操作的参数
//$taskId = $client->combineUpload($filePath);
//Tools::log_to_write_txt(['taskId'=>$taskId]);
//
//// 查询进度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);
$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);
// 设置转写参数
$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'];
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;
}
Tools::log_to_write_txt(['app_id:',$app_id]);
Tools::log_to_write_txt(['secret_key:',$secret_key]);
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);
$filePath = $tempFile;//'/Users/wh/Desktop/test.wav';
// 这里的$app_id、$secret_key是在开放平台控制台获得
$client = new LfasrClient($app_id, $secret_key, $lfasrConfig);
Tools::log_to_write_txt(['初始化$client:'=>$client]);
if(empty($client)){
Tools::log_to_write_txt(['初始化client初始化失败:$client为空。'=>$client]);
return;
}
if ($data['status'] == 9) {
// $filePath为待转写的本地文件路径返回taskId作为后续查询进度、获取结果操作的参数
$taskId = $client->combineUpload($filePath);
Tools::log_to_write_txt(['taskId'=>$taskId]);
$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);
// 查询进度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);
//// 处理翻译结果,例如保存到数据库或返回给前端
//Gateway::sendToClient($client_id, $result);
}