有没有PHP例子
yongdel 发布于2016-12-16 浏览:1024 回复:1
0
收藏
快速回复

有没有PHP例子,谢谢!

收藏
点赞
0
个赞
共1条回复 最后由nickms回复于2016-12-19
#2nickms回复于2016-12-19

yongdel:

有没有PHP例子,谢谢!

回复yongdel:

//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
切换版块