PHP call big signal voice service
recently made WeChat small programs, need to do voice recognition, select the famous voice of the home.
my background is PHP, taking some pits in the access process, here to share the friend
to apply for
apply for the flight account number http://www.xfyun.cn/
to write a picture description
add IP white list (5-10 minutes into effect)
Prepare an audio file (WAV or PCM format)
[code]const APP_ID ='xxxx';
[code]const APP_ID ='xxxx'; / / / / voice dictation = = / / / voice synthesis Y.lt; /code.gt;
voice dictation
.lt; code.gt; public function voiceIat ($file_path) {
$param =; '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'
.#93; //Body
$file_path = $; = file_get_contents ($file_path); $body_data ='audio='.urlencode (base64_encode ($file_content)); //Request
$url =.Quot; http://api.xfyun.cn/v1/service/v1/iat.quot; $ch = curl_init (); dialectical / > = > > > > > > > > > > > > > > > Curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($ch, CURLOPT_POST, TRUE);
curl_setopt. /code]
voice dictation examples:
[code]voiceIat ('a.wav'); [/code]
[code].#91; code.#93; public function voiceIse. 93;; $cur_time = (string) time (); $x_param = base64_encode (json_encode ($param)); $header_data =.#91;'X-Appid:'.self:: APP_ID.'X-CurTime:'.$cur_time. -www-form-urlencoded; charset=utf-8'
.#93;; //Body
$file_path = $file_path; $file_content = file_get_contents ($file_path); $body_data ='audio='.urlencode. .quot; $ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0); L_setopt ($ch, CURLOPT_POSTFIELDS, $body_data); $result = curl_exec ($ch);
}.#91; /code.#93
.#91; code.#93 echo; voiceIse ('a.wav',' a really awesome news fly ');.#91; /code.#93;
public function V: speech synthesis OiceTts ($content, $output_path) {
$param =.#91;'engine_type'=.gt;'intp65','auf'=.gt;'audio/L16. (json_encode ($param)); $header_data =.#91;'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; Br / > $body_data ='text='.urlencode ($content); //Request
$url =.Quot; http://api.xfyun.cn/v1/service/v1/tts.quot; $ch = curl_init ();
curl_setopt. RUE);
curl_setopt ($ch, CURLOPT_POST, TRUE);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header_data);
. $res_header_size);
curl_close ($ch); if (stripos ($res_header,'Content-Type: audio/mpeg') = = = FALSE) {/ / / / / / > > return / >; Sound synthesis is successful, please check the file! }
}
[/code]
[code]echo voiceTts speech synthesis (example:' iFLYTEK really awesome ','a.wav'); [/code]