在线API
配置参数
/*在线API*/
$CONF = array(
"AppID" => "176194**",
"appKey" => "y73Sj7RYjw7B**",
"appSecret" => "EQMb0r5GUNL8i**",
);
获取token
$url = "http://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=" . $CONF["appKey"] . "&client_secret=" . $CONF["appSecret"];
$http = json_decode(file_get_contents($url));
获取音频地址
$txtHttp = "http://tsn.baidu.com/text2audio?lan=zh&ctp=1&cuid=abcdxxx&tok=" . $http->access_token . "&tex=%e7%99%be%e5%ba%a6%e4%bd%a0%e5%a5%bd&vol=9&per=0&spd=5&pit=5&aue=3";
PHP-SDK
配置参数 同上;
引入依赖包;
require_once 'libs/AipSpeech.php';
$client = new AipSpeech($CONF["AppID"], $CONF["appKey"], $CONF["appSecret"]);
获取音频地址
$result = $client->synthesis('漏刻有时数据可视化LOCKDATAV', 'zh', 1, array(
'vol' => 5,
'per' => 4,
));
// 识别正确返回语音二进制 错误则返回json 参照下面错误码
if (!is_array($result)) {
file_put_contents('audio.mp3', $result);
}
Done!