如何将Azure认知服务文本(TTS)归为MP3文件?继续
我正在使用Azure认知服务与PHP和Curl结合使用文本到语音(TTS),而当我获得输出时,我无法获得任何可用的东西,因为我需要MP3文件作为输出。
这是我的代码:
$token = getAccessToken();
////$token=getToken();
$cont='<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-US">
<voice name="en-US-ChristopherNeural">
Testing testing 123
</voice>
</speak>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://eastus.tts.speech.microsoft.com/cognitiveservices/v1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($cont));
curl_setopt($ch, CURLOPT_HEADER, 1);
$headers = array();
$headers[] = 'Ocp-Apim-Subscription-Key: xxxxxxxxxxxxxxxx';
$headers[] = 'Content-Type: application/ssml+xml';
$headers[] = 'Host: eastus.tts.speech.microsoft.com';
$headers[] = 'Content-Length: '.strlen($cont);
$headers[] = 'Authorization: Bearer '.$token;//Token okay
$headers[] = 'User-Agent: EasternServer';
$headers[] = 'X-Microsoft-OutputFormat: raw-24khz-16bit-mono-pcm';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
echo $result;
I am using Azure Cognitive Services with text to speech (tts) in combination with PHP and Curl and while I am getting output, I am not getting anything usable as I need an MP3 file as an output.
Here is my code:
$token = getAccessToken();
////$token=getToken();
$cont='<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-US">
<voice name="en-US-ChristopherNeural">
Testing testing 123
</voice>
</speak>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://eastus.tts.speech.microsoft.com/cognitiveservices/v1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($cont));
curl_setopt($ch, CURLOPT_HEADER, 1);
$headers = array();
$headers[] = 'Ocp-Apim-Subscription-Key: xxxxxxxxxxxxxxxx';
$headers[] = 'Content-Type: application/ssml+xml';
$headers[] = 'Host: eastus.tts.speech.microsoft.com';
$headers[] = 'Content-Length: '.strlen($cont);
$headers[] = 'Authorization: Bearer '.$token;//Token okay
$headers[] = 'User-Agent: EasternServer';
$headers[] = 'X-Microsoft-OutputFormat: raw-24khz-16bit-mono-pcm';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
echo $result;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如OP所提到的,该问题已得到解决。
(将发现结果作为答案发布,以便将来有人遇到类似问题时,他可以在此线程上找到解决方案。这对其他社区贡献者将有帮助)
当文本到语音的原始输出流时,该问题已得到解决转换已在目标位置保存为
.mp3
文件扩展名。As mentioned by the OP that the issue has been resolved.
(Posting the findings as an answer so that if someone faced the similar issue in future, he would get the solution on this thread. This will be helpful for other community contributors)
The issue has been resolved when the raw output stream in text to speech conversion has been saved as a
.mp3
file extension at the destination.