我正在尝试按照下面链接中的教程在 php 中实现 Microsoft 文本到语音。
这是 API 示例发布请求
POST /cognitiveservices/v1 HTTP/1.1
X-Microsoft-OutputFormat: raw-16khz-16bit-mono-pcm
Content-Type: application/ssml+xml
Host: westus.tts.speech.microsoft.com
Content-Length: 225
Authorization: Bearer [Base64 access_token]
<speak version='1.0' xml:lang='en-US'><voice xml:lang='en-US' xml:gender='Female'
name='en-US-AriaRUS'>
Microsoft Speech Service Text-to-Speech API
</voice></speak>
我已经获得了我的访问令牌。
这是我的问题。 如何添加我将转换为语音的文本。我试过这个
$params = "Hello I need to be converted to Voice";
但什么也没发生。没有错误消息。
这是到目前为止的完整编码
$url = 'https://westus.tts.speech.microsoft.com/cognitiveservices/v1';
$curl = curl_init();
$params = "Hello I need to be converted to Voice";
$myApp_name = 'Text-to-Speech-App';
$header = [
"Authorization: Bearer mytoken-goes-here",
"Content-Type: application/ssml+xml",
"X-Microsoft-OutputFormat: raw-16khz-16bit-mono-pcm",
"User-Agent: $myApp_name",
"Content-Length:". strlen($params)
];
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
echo $response = curl_exec($curl);
慕仙森
catspeake
慕尼黑5688855
胡说叔叔