21,893
社区成员




<?php
//用户参数
$apikey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$appid = 'xxxxxxx';
$CurTime = (string)time();
$audioType = 'raw';
//语音参数
$json = array('aue' => $audioType, 'auf' => 'audio/L16;rate=16000', 'voice_name' => 'xiaoyan');
$param = base64_encode(utf8_encode(json_encode($json, JSON_UNESCAPED_SLASHES)));
$body = 'text=讯飞是中国最大的智能语音技术提供商';
//验证参数
$checkSum = md5($apikey . $CurTime . $param);
//http头
$header = array(
'X-Appid:' . $appid,
'X-CurTime:' . $CurTime,
'X-Param:' . $param,
'X-CheckSum:' . $checkSum,
);
//请求
$url = 'http://api.xfyun.cn/v1/service/v1/tts';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$result = curl_exec($ch);
curl_close($ch);
//处理响应
echo($result);
$saveType = $audioType == 'raw' ? '.wav' : '.mp3';
$saveName = $CurTime . $saveType;
// TODO:save wav file