From ddd75f8a00eed0258c6ce5fa1014ca279c4efaa9 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 14 Oct 2023 12:00:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=AD=A3=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Pusher.php | 15 ++------------- app/controller/IndexController.php | 3 ++- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/app/Pusher.php b/app/Pusher.php index 2b5cbe9..94ff861 100644 --- a/app/Pusher.php +++ b/app/Pusher.php @@ -95,20 +95,9 @@ class Pusher } $connection->send($response); } else { - $a=$resp['payload']['choices']['text'][0]['content']; - if(strlen($a)>0){ - $pattern = "/[。]/"; - if (preg_match($pattern, $a)) { - $resp['payload']['choices']['tts_text'] = $text; - } else { - $resp['payload']['choices']['tts_text'] = $text.$a; - // $this->tts($text.$a); - } - }else{ - $resp['payload']['choices']['tts_text'] = $text.$a; - // $this->tts($text.$a); - } + $resp['payload']['choices']['tts_text'] = $text.$resp['payload']['choices']['text'][0]['content']; + // $this->tts($text.$a); $text = ''; $response = json_encode($resp, true); diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index 87bfc20..4558f15 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -56,7 +56,8 @@ class IndexController public function tts(Request $request){ $text = $request->post('data'); - if($text!=''){ + $pattern = "/[\x{4e00}-\x{9fa5}\d]+/u"; + if( preg_match($pattern, $text)){ $name = time() . rand(1, 100000) . '.mp3'; $tts = new TtsClient($this->app_id, $this->api_key, $this->api_secret, $this->ttsConfig); file_put_contents(public_path('tts') . '/' . $name, $tts->request($text)->getBody()->getContents());