Hi
Was trying to generate a simple t2s mp3 using the api with php. unfortunately the api is generating all the time 415byte mp3 files. I’ve just taken the example php code from the community here. Is there anything new - the example code is from Nov. 23 , but comparing it to curl code seems to be ok.
Cheers
Adam
$openai_api_key = ‘12345678910’; // Replaced it with my actual API key
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ‘https: // api.openai. com/v1/audio/speech’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ’ . $openai_api_key,
‘Content-Type: application/json’
));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
‘model’ => ‘tts-1’,
‘input’ => ‘Today is a wonderful day to build something people love!’,
‘voice’ => ‘alloy’
)));
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo ‘Error:’ . curl_error($ch);
} else {
// Saving the result as an MP3 file
file_put_contents(‘speech.mp3’, $result);
}
curl_close($ch);