RT,有没有方法用PHP来调用语音合成接口?
之前为别人提供过,仅作参考:
//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);?>
之前为别人提供过,仅作参考:
//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);
?>