成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

實(shí)現(xiàn)php語音到賬api接口的方法

小編給大家分享一下實(shí)現(xiàn)php語音到賬api接口的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

創(chuàng)新互聯(lián)長期為上1000+客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為泉州企業(yè)提供專業(yè)的成都網(wǎng)站建設(shè)、做網(wǎng)站,泉州網(wǎng)站改版等技術(shù)服務(wù)。擁有10余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。

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

1.準(zhǔn)備工作
申請訊飛帳號http://www.xfyun.cn/

實(shí)現(xiàn)php語音到賬api接口的方法

添加IP白名單(5-10分鐘生效)準(zhǔn)備一個(gè)音頻文件(wav或pcm格式)獲取APPID和APPKEY(每個(gè)服務(wù)的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){ //合成錯(cuò)誤
return substr($result, $res_header_size);
}else{
file_put_contents($output_path, substr($result, $res_header_size));
return ‘語音合成成功,請查看文件!’;
}
}

語音合成示例:

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

看完了這篇文章,相信你對實(shí)現(xiàn)php語音到賬api接口的方法有了一定的了解,想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

網(wǎng)站標(biāo)題:實(shí)現(xiàn)php語音到賬api接口的方法
分享URL:http://jinyejixie.com/article10/iieddo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)網(wǎng)站維護(hù)、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈、全網(wǎng)營銷推廣、虛擬主機(jī)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化
凤台县| 五华县| 凤山县| 横山县| 托里县| 岳池县| 彭州市| 怀安县| 吉水县| 望谟县| 马尔康县| 新巴尔虎左旗| 筠连县| 江北区| 偃师市| 拜泉县| 页游| 阿克陶县| 永济市| 稻城县| 吉水县| 布尔津县| 鄯善县| 祁阳县| 肥城市| 衡水市| 万宁市| 土默特右旗| 曲麻莱县| 江陵县| 天峨县| 中卫市| 承德市| 乐平市| 马尔康县| 兴海县| 大同市| 福建省| 陆良县| 澄江县| 定州市|