更新
This commit is contained in:
parent
09ae2194d2
commit
4e752ff1fe
@ -2,12 +2,26 @@
|
|||||||
|
|
||||||
namespace app\controller;
|
namespace app\controller;
|
||||||
|
|
||||||
|
use app\extend\IFlytek\Xfyun\Speech\TtsClient;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use Webman\Container;
|
use Webman\Container;
|
||||||
use Webman\Push\Api;
|
use Webman\Push\Api;
|
||||||
|
|
||||||
class IndexController
|
class IndexController
|
||||||
{
|
{
|
||||||
|
private $app_id = '2eda6c2e';
|
||||||
|
|
||||||
|
private $api_key = '12ec1f9d113932575fc4b114a2f60ffd';
|
||||||
|
|
||||||
|
private $api_secret = 'MDEyMzE5YTc5YmQ5NjMwOTU1MWY4N2Y2';
|
||||||
|
|
||||||
|
|
||||||
|
private $ttsConfig = [
|
||||||
|
'aue' => 'lame',
|
||||||
|
'sfl' => 1,
|
||||||
|
'vcn' => 'x4_lingxiaoyao_en'
|
||||||
|
];
|
||||||
|
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
return json(['code' => 0, 'msg' => 'ok']);
|
return json(['code' => 0, 'msg' => 'ok']);
|
||||||
@ -39,4 +53,17 @@ class IndexController
|
|||||||
]);
|
]);
|
||||||
return json(['code' => 0, 'msg' => 'ok']);
|
return json(['code' => 0, 'msg' => 'ok']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tts(Request $request){
|
||||||
|
$text = $request->post('data');
|
||||||
|
if($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());
|
||||||
|
return json(['code' => 0, 'msg' => 'ok','data'=>['mp3'=>'https://chat.lihaink.cn/tts/' . $name]]);
|
||||||
|
}
|
||||||
|
return json(['code' => 0, 'msg' => 'ok']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user