PHP call big signal voice service

time:18-04-22 forum:PHP tools and code
  http://www.php.cn/php-weizijiaocheng-392613.html

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]

prev:New tricks for old people's Hoax: specia... next:Dr. Ph. D. wrote a paper explaining what...
post comment
Notice



approved   The 3 year old was elected the young...   The Qilu Public Welfare Alliance has...   Beautiful and impressive: the nights...   Ji'nan Ying Bi Street School: specia...   Reminder: at present, there are only...
rand   The interrotation of time stamp func...      Website 301 turn to Encyclopedia   Super PHP rapid programmer   PHP regular expression summary
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com