更新正则

This commit is contained in:
mkm 2023-10-14 12:00:46 +08:00
parent a6407044ff
commit ddd75f8a00
2 changed files with 4 additions and 14 deletions

View File

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

View File

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