有没有PHP例子,谢谢!
yongdel:
回复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;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
var_dump($response);
file_put_contents("2.mp3", $response, FILE_APPEND);
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);