From 756be58d0f6c97fe0bdae3e2cddaac6bfefc526d Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Tue, 10 Oct 2023 14:13:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=AD=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/XunFeiController.php | 36 ++++++++++--------- .../IFlytek/Xfyun/Speech/Config/TtsConfig.php | 1 - 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/api/controller/XunFeiController.php b/app/api/controller/XunFeiController.php index d0ecb933d..604d62b51 100644 --- a/app/api/controller/XunFeiController.php +++ b/app/api/controller/XunFeiController.php @@ -241,27 +241,29 @@ class XunFeiController extends BaseApiController { header('X-Accel-Buffering: no'); $ttsHostUrl = "wss://tts-api.xfyun.cn/v2/tts"; - $text = request()->file('text'); - if(empty($file)){ + $text = request()->param('text'); + if(empty($text)){ return $this->fail('未上传文本参数'); } - $business = [ - 'aue' => 'lame', - 'vcn' => 'xiaoyan', - 'auf' => 'audio/L16;rate=16000', - 'speed' => 50, - 'volume'=> 100, - 'pitch' => 50, - 'tte' => 'UTF8', - ]; - $tts = new TtsClient($this->app_id,$this->api_key,$this->api_secret, $business); $date = date('YmdHis', time()); - $file_name = $date . '.mp3'; + $file_name = $date . mt_rand(1000, 9999) . '.mp3'; $audioFile = app()->getRootPath() . '/runtime/storage/audio/' . date('Ymd') . '/' . $file_name; - file_put_contents($audioxxxFile, $tts->request($text)->getBody()->getContents()); - exit; - - + $business = [ + 'aue' => 'lame', //mp3格式 + 'vcn' => 'xiaoyan', //发音人 + 'auf' => 'audio/L16;rate=16000', //音频采样率 + 'speed' => 50, //语速 + 'volume'=> 100, //音量 + 'pitch' => 50, //音高 + 'tte' => 'UTF8' + ]; + try { + $tts = new TtsClient($this->app_id, $this->api_key, $this->api_secret, $business); + file_put_contents($audioFile, $tts->request($text)->getBody()->getContents()); + } catch (\Exception $e) { + return $this->fail($e->getMessage().''); + } + return $this->data(['audio_file' => $audioFile]); } } diff --git a/extend/IFlytek/Xfyun/Speech/Config/TtsConfig.php b/extend/IFlytek/Xfyun/Speech/Config/TtsConfig.php index 69d5bb871..b1196e066 100644 --- a/extend/IFlytek/Xfyun/Speech/Config/TtsConfig.php +++ b/extend/IFlytek/Xfyun/Speech/Config/TtsConfig.php @@ -154,7 +154,6 @@ class TtsConfig implements ConfigInterface $this->reg = $config['reg']; $this->rdn = $config['rdn']; $this->ent = $config['ent']; - print_r($config); } /**