'How do I outtput Azure cognitive services Text to speech (TTS) to MP3 file? Keep getting

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;


Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 UtkarshPal-MT