...
|
...
|
@@ -13,6 +13,7 @@ use app\mobile\model\QuestionAnswer; |
|
|
use app\mobile\model\QuestionNote;
|
|
|
use app\mobile\model\QuestionWrong;
|
|
|
use app\mobile\model\QuestionCollect;
|
|
|
use addons\qiniu\library\Auth;
|
|
|
|
|
|
/**
|
|
|
* 全能题库接口
|
...
|
...
|
@@ -340,6 +341,34 @@ class Almighty extends Api |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (智能搜题-语音转文字)
|
|
|
* @ApiSummary (智能搜题-语音转文字)
|
|
|
* @ApiMethod (POST)
|
|
|
*
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
*
|
|
|
* @ApiParams (name="filename", type="string", required=true, description="文件地址")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1599130815",
|
|
|
"data": [{
|
|
|
"id": 1, //题目ID
|
|
|
"title": "测定混凝土立方体抗压强度时,标准试件的尺寸是( )㎜。", //题目
|
|
|
"type": "4", //题目类型:1=单选题,2=多选题,3=判断题,4=简答题
|
|
|
"option": "[{\"name\":\"A\",\"gender\":\"100\\u00d7100\\u00d7100\"},{\"name\":\"B\",\"gender\":\"150\\u00d7150\\u00d7150\"},{\"name\":\"C\",\"gender\":\"200\\u00d7200\\u00d7200\"},{\"name\":\"D\",\"gender\":\"70.7\\u00d770.7\\u00d770.7\"}]" //题目选项
|
|
|
}]
|
|
|
})
|
|
|
*/
|
|
|
public function getText()
|
|
|
{
|
|
|
$filename = $this->request->param('filename');
|
|
|
$res = $this->mp3ToPcm($filename);
|
|
|
$this->success('成功');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (智能搜题)
|
|
|
* @ApiSummary (智能搜题)
|
|
|
* @ApiMethod (POST)
|
...
|
...
|
@@ -457,4 +486,50 @@ class Almighty extends Api |
|
|
}
|
|
|
$this->success('成功',compact('banner','list'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 上传接口
|
|
|
*/
|
|
|
public function mp3ToPcm($filename)
|
|
|
{
|
|
|
$key = ltrim($filename,'/');
|
|
|
if(pathinfo($key,PATHINFO_EXTENSION) != 'mp3'){
|
|
|
return false;
|
|
|
}
|
|
|
$config = get_addon_config('qiniu');
|
|
|
$auth = new Auth($config['app_key'], $config['secret_key']);
|
|
|
//设置转码参数
|
|
|
$fops = "avthumb/pcm/ab/192k";
|
|
|
//通过添加'|saveas'参数,指定处理后的文件保存的bucket和key 不指定默认保存在当前空间,bucket为目标空间,后一个参数为转码之后文件名
|
|
|
$filename = str_replace(strrchr($key, "."),"",$key);
|
|
|
$entry = $config['bucket'] . ':' . $filename . '.pcm';
|
|
|
$saveas_key = $auth->base64_urlSafeEncode($entry);
|
|
|
|
|
|
$fops = $fops.'|saveas/'.$saveas_key;
|
|
|
|
|
|
$policy = array(
|
|
|
'persistentOps' => $fops
|
|
|
);
|
|
|
$token = $auth->uploadToken($config['bucket'], null, $config['expire'], $policy);
|
|
|
$multipart = [
|
|
|
['name' => 'token', 'contents' => $token],
|
|
|
[
|
|
|
'name' => 'file',
|
|
|
'contents' => fopen('/'.$key, 'r'),
|
|
|
'filename' => $key,
|
|
|
]
|
|
|
];
|
|
|
try {
|
|
|
$client = new \GuzzleHttp\Client();
|
|
|
$res = $client->request('POST', $config['uploadurl'], [
|
|
|
'multipart' => $multipart
|
|
|
]);
|
|
|
halt($res);
|
|
|
$code = $res->getStatusCode();
|
|
|
//成功不做任何操作
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
|
|
return false;
|
|
|
}
|
|
|
return $code;
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|