PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > PHP教程 > 正文

    php语音识别接口调用代码实例

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:php语音识别接口调用代码实例,语音识别API,精准、快速、省流量
    语音识别API,精准、快速、省流量
    语音识别API:https://www.juhe.cn/docs/api/id/134

    PHP示例:


    1. <!--?php 
    2. //B5教程网 www.bcty365.com 
    3.   
    4. //---------------------------------- 
    5. // 语音识别调用示例代码 - 聚合数据 
    6. // 在线接口文档:http://www.juhe.cn/docs/134 
    7. //---------------------------------- 
    8.   
    9. header('Content-type:text/html;charset=utf-8'); 
    10.   
    11.   
    12. //配置您申请的appkey 
    13. $appkey = "*********************"
    14.   
    15.   
    16.   
    17.   
    18. //************1.语音识别接口************ 
    19. $url = "http://japi.juhe.cn/voice_words/getWords"
    20. $params = array( 
    21.       "key" => $appkey,//APP Key 
    22.       "file" => "",//上传的音频文件(采样率16k或者8k(rate),采样精度16bit(bit),单声道的pcm或者wav格式的音频) 
    23.       "rate" => "",//采样率(16000或者8000) 
    24.       "pname" => "",//包名 
    25.       "device_id" => "",//标记请求来源的标识,如用户所设备序列号 (SN),IMEI,MAC地址等 
    26. ); 
    27. $paramstring = http_build_query($params); 
    28. $content = juhecurl($url,$paramstring,1); 
    29. $result = json_decode($content,true); 
    30. if($result){ 
    31.     if($result['error_code']=='0'){ 
    32.         print_r($result); 
    33.     }else
    34.         echo $result['error_code'].":".$result['reason']; 
    35.     } 
    36. }else
    37.     echo "请求失败"
    38. //************************************************** 
    39.   
    40.   
    41.   
    42.   
    43.   
    44. /** 
    45.  * 请求接口返回内容 
    46.  * @param  string $url [请求的URL地址] 
    47.  * @param  string $params [请求的参数] 
    48.  * @param  int $ipost [是否采用POST形式] 
    49.  * @return  string 
    50.  */ 
    51. function juhecurl($url,$params=false,$ispost=0){ 
    52.     $httpInfo = array(); 
    53.     $ch = curl_init(); 
    54.   
    55.     curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); 
    56.     curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' ); 
    57.     curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 ); 
    58.     curl_setopt( $ch, CURLOPT_TIMEOUT , 60); 
    59.     curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true ); 
    60.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
    61.     if( $ispost ) 
    62.     { 
    63.         curl_setopt( $ch , CURLOPT_POST , true ); 
    64.         curl_setopt( $ch , CURLOPT_POSTFIELDS , $params ); 
    65.         curl_setopt( $ch , CURLOPT_URL , $url ); 
    66.     } 
    67.     else 
    68.     { 
    69.         if($params){ 
    70.             curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params ); 
    71.         }else
    72.             curl_setopt( $ch , CURLOPT_URL , $url); 
    73.         } 
    74.     } 
    75.     $response = curl_exec( $ch ); 
    76.     if ($response === FALSE) { 
    77.         //echo "cURL Error: " . curl_error($ch); 
    78.         return false
    79.     } 
    80.     $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE ); 
    81.     $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) ); 
    82.     curl_close( $ch ); 
    83.     return $response; 

     

    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-10-5370-1.html
    相关热词搜索: