百度语音代码
<?php //put your params here $cuid = "00-17-31-16-38-AE"; $apiKey = "t0p6WSEA3VbbckXLHr5rY3ne"; $secretKey = "f73abd354be5e19ff926f220bb9577e8"; $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_SSL_VERIFYPEER,0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $response = curl_exec($ch); if(curl_errno($ch)) { print curl_error($ch); } curl_close($ch); //var_dump($response); echo file_put_contents("saekv://2.mp3", $response, FILE_APPEND); //echo file_put_contents("test.txt","Hello World. Testing!"); ?>