如何将Azure认知服务文本到语音(TTS)转换为MP3文件?继续前进



我将Azure认知服务与文本到语音(tts(结合PHP和Curl一起使用,当我获得输出时,我没有得到任何可用的东西,因为我需要一个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;

正如OP所提到的,问题已经解决。

(将调查结果作为答案发布,这样,如果有人将来面临类似的问题,他就会在这个帖子上找到解决方案。这将对其他社区贡献者有所帮助(

当文本到语音转换中的原始输出流已在目的地保存为.mp3文件扩展名时,该问题已得到解决。

最新更新