diff --git a/app/api/controller/XunFeiController.php b/app/api/controller/XunFeiController.php index fb0074293..32b7705b1 100644 --- a/app/api/controller/XunFeiController.php +++ b/app/api/controller/XunFeiController.php @@ -126,14 +126,18 @@ class XunFeiController extends BaseApiController if(empty($file)){ return $this->fail('未上传音频文件'); } - // 上传到本地服务器 + // 上传音频临时文件 $savename = \think\facade\Filesystem::putFile('audio', $file); - $file = app()->getRootPath() .'/runtime/storage/' . $savename; + $file = app()->getRootPath() . '/runtime/storage/' . $savename; + if (!file_exists($file)) { + return $this->fail('未上传音频文件'); + } // $file = "https://lihai001.oss-cn-chengdu.aliyuncs.com/media/iat_mp3_16k.mp3"; $audioFile = fopen($file, 'rb'); if ($audioFile === false) { return $this->fail('音频文件异常'); } + $words = ''; $iatHostUrl = "wss://iat-api.xfyun.cn/v2/iat"; $iat = new IatClient($this->app_id,$this->api_key,$this->api_secret); $client = new Client($iat->assembleAuthUrl($iatHostUrl)); @@ -196,7 +200,6 @@ class XunFeiController extends BaseApiController //模拟音频采样间隔 usleep($intervel); } - $words = ''; while (true) { $response = $client->receive(); if ($response === null) {