
<?php
$language = $_REQUEST['language'];
$voice = $_REQUEST['voice'];
$text = trim($_REQUEST['text']);
$role = $_REQUEST['role'];
$style = $_REQUEST['style'];
$rate = $_REQUEST['rate'];
$pitch = $_REQUEST['pitch'];
$data = '<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="'.$language.'">
<voice name="'.$voice.'">
<mstts:express-as role="'.$role.'" style="'.$style.'">
<prosody rate="'.$rate.'%" pitch="'.$pitch.'%">
'.$text.'
</prosody>
</mstts:express-as>
</voice>
</speak>';
/*$data = '<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis"
xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="zh-CN">
<voice name="zh-CN-XiaomoNeural">
女儿看见父亲走了进来,问道:
<mstts:express-as role="YoungAdultFemale" style="calm">
“您来的挺快的,怎么过来的?”
</mstts:express-as>
父亲放下手提包,说:
<mstts:express-as role="OlderAdultMale" style="calm">
“刚打车过来的,路上还挺顺畅。”
</mstts:express-as>
</voice>
</speak>';*/
// echo($data);exit();
$region = "****"; // 此处需要申请个人账号 申请地址:https://azure.microsoft.com/zh-cn/products/cognitive-services/text-to-speech/#features
$AccessTokenUri = "https://".$region.".api.cognitive.microsoft.com/sts/v1.0/issueToken";
$apiKey = "*******"; // 个人密钥 同上方申请
$headerArray =array(
'header' => "Ocp-Apim-Subscription-Key: ".$apiKey."
" .
"content-length: 0
",
);
if (false) {
$result = array(
'code'=> 400,
'msg'=>"token获取失败,请联系管理员",
'author'=>"企业猫源码网",
'url'=>"https://www.qymao.cn/"
);
echo json_encode($result,320);
exit();
}else{
$ttsServiceUri = "https://".$region.".tts.speech.microsoft.com/cognitiveservices/v1";
$headers = "Content-type: application/ssml+xml
" .
"X-Microsoft-OutputFormat: audio-16khz-32kbitrate-mono-mp3
" .
"Ocp-Apim-Subscription-Key: ".$apiKey."
" .
//"Authorization: "."Bearer ".$access_token."
" .
"X-Search-AppId: 07D3234E49CE426DAA29772419F436CA
" .
"X-Search-ClientID: 1ECFAE91408841A480F00935DC390960
" .
"User-Agent: TTSPHP