From cc4e1feb1a654c7e587dc3a1e8f3fcdcd191a812 Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Tue, 10 Oct 2023 10:50:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B5=81=E5=BC=8F=E8=AF=AD?= =?UTF-8?q?=E9=9F=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/XunFeiController.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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) {