This commit is contained in:
mkm 2023-10-13 21:59:41 +08:00
parent 7b89e9bea2
commit 2e933457b9

View File

@ -74,6 +74,8 @@ class Pusher
if ($tts_type == 1) { if ($tts_type == 1) {
if (count($arr) == 2) { if (count($arr) == 2) {
$resp['payload']['choices']['tts_text'] = $text . $arr[0]; $resp['payload']['choices']['tts_text'] = $text . $arr[0];
$text = '';
// $this->tts( $text . $arr[0]);
unset($arr[0]); unset($arr[0]);
$tt=''; $tt='';
$pattern = "/[,.?!;:]/"; $pattern = "/[,.?!;:]/";
@ -83,10 +85,7 @@ class Pusher
} }
if ($tt!=''||preg_match($pattern, $tt)) { if ($tt!=''||preg_match($pattern, $tt)) {
$text.=$tt; $text.=$tt;
} else {
$text = '';
} }
$response = json_encode($resp, true); $response = json_encode($resp, true);
} else { } else {
$resp['payload']['choices']['tts_text'] = ''; $resp['payload']['choices']['tts_text'] = '';
@ -103,9 +102,12 @@ class Pusher
$resp['payload']['choices']['tts_text'] = $text; $resp['payload']['choices']['tts_text'] = $text;
} else { } else {
$resp['payload']['choices']['tts_text'] = $text.$a; $resp['payload']['choices']['tts_text'] = $text.$a;
// $this->tts($text.$a);
} }
}else{ }else{
$resp['payload']['choices']['tts_text'] = $text.$a; $resp['payload']['choices']['tts_text'] = $text.$a;
// $this->tts($text.$a);
} }
$text = ''; $text = '';
$response = json_encode($resp, true); $response = json_encode($resp, true);
@ -206,9 +208,14 @@ class Pusher
function tts($text) function tts($text)
{ {
$name = time() . rand(1, 100000) . '.mp3'; $client = new AsyncTcpConnection('ws://0.0.0.0:8484');
$tts = new extend\IFlytek\Xfyun\Speech\TtsClient($this->app_id, $this->api_key, $this->api_secret, $this->ttsConfig); $data = $this->getBody($this->app_id, ["content"=> "你好"]);
file_put_contents(public_path('tts') . '/' . $name, $tts->request($text)->getBody()->getContents());
return 'https://chat.lihaink.cn/tts/' . $name; $client->send($data);
var_dump(22222);
// $name = time() . rand(1, 100000) . '.mp3';
// $tts = new extend\IFlytek\Xfyun\Speech\TtsClient($this->app_id, $this->api_key, $this->api_secret, $this->ttsConfig);
// file_put_contents(public_path('tts') . '/' . $name, $tts->request($text)->getBody()->getContents());
// return 'https://chat.lihaink.cn/tts/' . $name;
} }
} }