语音合成有PHP的接口么
Tom_cat2012 发布于2017-02 浏览:2207 回复:1
0
收藏

RT,有没有方法用PHP来调用语音合成接口?

收藏
点赞
0
个赞
共1条回复 最后由用户已被禁言回复于2022-04
#2nickms回复于2017-02

之前为别人提供过,仅作参考:


//put your params here
$cuid = "";
$apiKey = "";
$secretKey = "";

$auth_url = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=".$apiKey."&client_secret=".$secretKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $auth_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$response = curl_exec($ch);
if(curl_errno($ch))
{
    print curl_error($ch);
}
curl_close($ch);
$response = json_decode($response, true);
$token = $response['access_token'];

$url = "http://tsn.baidu.com/text2audio?";
$param = "tex=123&lan=zh&ctp=1&cuid=".urlencode(urlencode($cuid))."&tok=".urlencode(urlencode($token));
$url =  $url.$param;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
if(curl_errno($ch))
{
    print curl_error($ch);
}
curl_close($ch);
var_dump($response);
file_put_contents("2.mp3", $response, FILE_APPEND);

?>

0
TOP
切换版块