作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

七牛云配置

@@ -181,7 +181,7 @@ return array ( @@ -181,7 +181,7 @@ return array (
181 'content' => 181 'content' =>
182 array ( 182 array (
183 ), 183 ),
184 - 'value' => 'jpg,png,bmp,jpeg,gif,zip,rar,xls,xlsx,mp4,wma,docx,ppt,pdf,pptx,xls,xlsx,pcm', 184 + 'value' => 'jpg,png,bmp,jpeg,gif,zip,rar,xls,xlsx,mp4,wma,docx,ppt,pdf,pptx,xls,xlsx,pcm,mp3',
185 'rule' => 'required', 185 'rule' => 'required',
186 'msg' => '', 186 'msg' => '',
187 'tip' => '', 187 'tip' => '',
@@ -13,6 +13,7 @@ use app\mobile\model\QuestionAnswer; @@ -13,6 +13,7 @@ use app\mobile\model\QuestionAnswer;
13 use app\mobile\model\QuestionNote; 13 use app\mobile\model\QuestionNote;
14 use app\mobile\model\QuestionWrong; 14 use app\mobile\model\QuestionWrong;
15 use app\mobile\model\QuestionCollect; 15 use app\mobile\model\QuestionCollect;
  16 +use addons\qiniu\library\Auth;
16 17
17 /** 18 /**
18 * 全能题库接口 19 * 全能题库接口
@@ -340,6 +341,34 @@ class Almighty extends Api @@ -340,6 +341,34 @@ class Almighty extends Api
340 } 341 }
341 342
342 /** 343 /**
  344 + * @ApiTitle (智能搜题-语音转文字)
  345 + * @ApiSummary (智能搜题-语音转文字)
  346 + * @ApiMethod (POST)
  347 + *
  348 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  349 + *
  350 + * @ApiParams (name="filename", type="string", required=true, description="文件地址")
  351 + *
  352 + * @ApiReturn({
  353 + "code": 1,
  354 + "msg": "成功",
  355 + "time": "1599130815",
  356 + "data": [{
  357 + "id": 1, //题目ID
  358 + "title": "测定混凝土立方体抗压强度时,标准试件的尺寸是( )㎜。", //题目
  359 + "type": "4", //题目类型:1=单选题,2=多选题,3=判断题,4=简答题
  360 + "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\"}]" //题目选项
  361 + }]
  362 + })
  363 + */
  364 + public function getText()
  365 + {
  366 + $filename = $this->request->param('filename');
  367 + $res = $this->mp3ToPcm($filename);
  368 + $this->success('成功');
  369 + }
  370 +
  371 + /**
343 * @ApiTitle (智能搜题) 372 * @ApiTitle (智能搜题)
344 * @ApiSummary (智能搜题) 373 * @ApiSummary (智能搜题)
345 * @ApiMethod (POST) 374 * @ApiMethod (POST)
@@ -457,4 +486,50 @@ class Almighty extends Api @@ -457,4 +486,50 @@ class Almighty extends Api
457 } 486 }
458 $this->success('成功',compact('banner','list')); 487 $this->success('成功',compact('banner','list'));
459 } 488 }
  489 +
  490 + /**
  491 + * 上传接口
  492 + */
  493 + public function mp3ToPcm($filename)
  494 + {
  495 + $key = ltrim($filename,'/');
  496 + if(pathinfo($key,PATHINFO_EXTENSION) != 'mp3'){
  497 + return false;
  498 + }
  499 + $config = get_addon_config('qiniu');
  500 + $auth = new Auth($config['app_key'], $config['secret_key']);
  501 + //设置转码参数
  502 + $fops = "avthumb/pcm/ab/192k";
  503 + //通过添加'|saveas'参数,指定处理后的文件保存的bucket和key 不指定默认保存在当前空间,bucket为目标空间,后一个参数为转码之后文件名
  504 + $filename = str_replace(strrchr($key, "."),"",$key);
  505 + $entry = $config['bucket'] . ':' . $filename . '.pcm';
  506 + $saveas_key = $auth->base64_urlSafeEncode($entry);
  507 +
  508 + $fops = $fops.'|saveas/'.$saveas_key;
  509 +
  510 + $policy = array(
  511 + 'persistentOps' => $fops
  512 + );
  513 + $token = $auth->uploadToken($config['bucket'], null, $config['expire'], $policy);
  514 + $multipart = [
  515 + ['name' => 'token', 'contents' => $token],
  516 + [
  517 + 'name' => 'file',
  518 + 'contents' => fopen('/'.$key, 'r'),
  519 + 'filename' => $key,
  520 + ]
  521 + ];
  522 + try {
  523 + $client = new \GuzzleHttp\Client();
  524 + $res = $client->request('POST', $config['uploadurl'], [
  525 + 'multipart' => $multipart
  526 + ]);
  527 + halt($res);
  528 + $code = $res->getStatusCode();
  529 + //成功不做任何操作
  530 + } catch (\GuzzleHttp\Exception\ClientException $e) {
  531 + return false;
  532 + }
  533 + return $code;
  534 + }
460 } 535 }
此 diff 太大无法显示。