如何将Azure认知服务文本(TTS)归为MP3文件?继续

发布于 2025-01-20 06:24:23 字数 1178 浏览 5 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房敞 2025-01-27 06:24:23

正如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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文