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());