欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          php語音到賬api接口如何實現(xiàn)

          php語音到賬api接口如何實現(xiàn)

          php語音到賬api接口如何實現(xiàn)

          1.準備工作
          申請訊飛帳號http://www.xfyun.cn/

          php語音到賬api接口如何實現(xiàn)

          添加IP白名單(5-10分鐘生效)準備一個音頻文件(wav或pcm格式)獲取APPID和APPKEY(每個服務的APPKEY不同)

          const APP_ID = ‘xxxx’; const APP_KEY_IAT = ‘xxxx’; //語音聽寫APPKEY const APP_KEY_ISE = ‘xxxx’; //語音評測APPKEY const APP_KEY_TTS = ‘xxxx’; //語音合成APPKEY

          語音聽寫

          public function voiceIat($file_path) { $param = [ ‘engine_type’ => ‘sms16k’, ‘a(chǎn)ue’ => ‘raw’ ]; $cur_time = (string)time(); $x_param = base64_encode(json_encode($param)); $header_data = [ ‘X-Appid:’.self::APP_ID, ‘X-CurTime:’.$cur_time, ‘X-Param:’.$x_param, ‘X-CheckSum:’.md5(self::APP_KEY_IAT.$cur_time.$x_param), ‘Content-Type:application/x-www-form-urlencoded; charset=utf-8’ ]; //Body $file_path = $file_path; $file_content = file_get_contents($file_path); $body_data = ‘a(chǎn)udio=’.urlencode(base64_encode($file_content)); //Request $url = “http://api.xfyun.cn/v1/service/v1/iat”; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_HTTPHEADER, $header_data); curl_setopt($ch, CURLOPT_POSTFIELDS, $body_data); $result = curl_exec($ch); curl_close($ch); return $result; }

          語音聽寫示例:

          voiceIat('a.wav');

          語音評測

          public function voiceIse($file_path, $content) { $param = [ ‘language’ => ‘cn’, ‘a(chǎn)ue’ => ‘raw’, ‘category’ => ‘read_sentence’ ]; $cur_time = (string)time(); $x_param = base64_encode(json_encode($param)); $header_data = [ ‘X-Appid:’.self::APP_ID, ‘X-CurTime:’.$cur_time, ‘X-Param:’.$x_param, ‘X-CheckSum:’.md5(self::APP_KEY_ISE.$cur_time.$x_param), ‘Content-Type:application/x-www-form-urlencoded; charset=utf-8’ ]; //Body $file_path = $file_path; $file_content = file_get_contents($file_path); $body_data = ‘a(chǎn)udio=’.urlencode(base64_encode($file_content)).’&text=’.urlencode($content); $url = “http://api.xfyun.cn/v1/service/v1/ise”; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_HTTPHEADER, $header_data); curl_setopt($ch, CURLOPT_POSTFIELDS, $body_data); $result = curl_exec($ch); curl_close($ch); return $result; }

          語音評測示例:

          echo voiceIse(‘a(chǎn).wav’, ‘科大訊飛真給力’);

          語音合成:

          public function voiceTts($content, $output_path) { $param = [ ‘engine_type’ => ‘intp65’, ‘a(chǎn)uf’ => ‘a(chǎn)udio/L16;rate=16000’, ‘a(chǎn)ue’ => ‘raw’, ‘voice_name’ => ‘xiaoyan’, ‘speed’ => ‘0’ ]; $cur_time = (string)time(); $x_param = base64_encode(json_encode($param)); $header_data = [ ‘X-Appid:’.self::APP_ID, ‘X-CurTime:’.$cur_time, ‘X-Param:’.$x_param, ‘X-CheckSum:’.md5(self::APP_KEY_TTS.$cur_time.$x_param), ‘Content-Type:application/x-www-form-urlencoded; charset=utf-8’ ]; //Body $body_data = ‘text=’.urlencode($content); //Request $url = “http://api.xfyun.cn/v1/service/v1/tts”; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_HTTPHEADER, $header_data); curl_setopt($ch, CURLOPT_POSTFIELDS, $body_data); $result = curl_exec($ch); $res_header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $res_header = substr($result, 0, $res_header_size); curl_close($ch); if(stripos($res_header, ‘Content-Type: audio/mpeg’) === FALSE){ //合成錯誤 return substr($result, $res_header_size); }else{ file_put_contents($output_path, substr($result, $res_header_size)); return ‘語音合成成功,請查看文件!’; } }

          語音合成示例:

          echo voiceTts(‘科大訊飛真給力’, ‘a(chǎn).wav’);

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號