//*
-----------------
//百度语音识别呼叫系统
-----------------
class freeApi{
private $ API密钥=false; //百度APP appid
私有$ secret key=false; //百度是bmdhxc Key
private $ token URL=' https://AIP.Baidu BCE.com/oauth/2.0/token ';
private $ API URL=' https://VOP.Baidu.com/server _ API ';
公共函数_ _ construct ($ API key,$secretkey ) {
$this-apiKey=$apikey;
$this-secretKey=$secretkey;
}
//*
公共函数获取
$params=[
' grant _ type '=' client _ credentials ',
' client_id'=$this-apiKey,
' client_secret'=$this-secretKey,
];
$o=' ';
Foreach($Paramsas$k=$v ) ) ) ) ) ) )。
{
$o.='$k='.urlencode($v ).';
}
$params=substr($o,0,-1);
返回$ this -返回阵列($ this-freeapicurl ) $this-tokenURL,$params,1 ) );
}
//*
publicfunctionreturnarray ($ content ) {
returnJSON_decode($content,true );
}
//*
公共功能获取结果
$ speech=file _ get _ contents (http://speech-doc.gz.BCE Bos.com/rest-API-ASR/public _ audio/16k.PCM
$len=Strlen($speech );
$params=[
" format'='pcm ",
' rate'=16000,
' dev_pid'=1536,
“信道”=1,
' token'=$this-getToken () ['access_token'],
' cuid'='baidu_workshop ',
' len'=$len,
' speech'=base64_encode($speech ),
];
$Params=JSON_encode($Params );
return $ this-return array ($ this-JSON post ) $this-APIURL,$params;
}
publicfunctionJSONpost($URL,$data_json ) )。
$ch=curl_init (;
CURL_setopt($ch,CURLOPT_URL,$url );
curl_setopt($ch,CURLOPTtmdc,array ) (content-type : application/JSON ) );
CURL_setopt($ch,CURLOPT_POST,1 );
CURL_setopt($ch,CURLOPT_POSTFIELDS,$data_json );
CURL_setopt($ch,CURLOPT_RETURNTRANSFER,true );
$response=curl_exec($ch );
CURL_close($ch;
return $response;
}
//*
publicfunctionfreeapicurl($URL,$params=false,$ispost=0) {
$httpInfo=array (;
$ch=curl_init (;
CURL_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
CURL_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
CURL_setopt($ch,CURLOPT_USERAGENT,' free-api ' );
CURL_setopt($ch,CURLOPT_CONNECTTIMEOUT,60 );
CURL_setopt($ch,CURLOPT_TIMEOUT,60 );
CURL_setopt($ch,CURLOPT_RETURNTRANSFER,true );
if($ispost ) )。
{
CURL_setopt($ch,CURLOPT_POST,true );
CURL_setopt($ch,CURLOPT_POSTFIELDS,$params );
CURL_setopt($ch,CURLOPT_URL,$url );
}
else
{
if($Params ) (
CURL_setopt($ch,CURLOPT_URL,$url.'? $params;
}else{
CURL_setopt($ch,CURLOPT_URL,$url );
}
}
$response=curl_exec($ch );
if { $ response==false }
返回假;
}
$httpcode=curl_getinfo($ch,CURLINFO_HTTP_CODE );
$ http info=array _ merge ($ http info,curl_getinfo ) $ch );
CURL_close($ch;
return $response;
}
}