How to send audio file to Whisper API

Hello,

I need some help I’m using the following code in php to translate an audio to text, but I always get the same error.
{
“success”: false,
“message”: “An error occurred: A ‘contents’ key is required”
}

When I add key contents it tells me that the file field is missing

// Make API request to transcribe audio
$response = $client->post(‘https://api.openai.com/v1/audio/transcriptions’, [
‘headers’ => [
‘Authorization’ => “Bearer {$apiKey}”,
‘Content-Type’ => ‘application/json’,
],
‘multipart’ => [
[
‘name’ => ‘audio_file’,
‘file’ => fopen($audioPath, ‘r’),
]
],
‘json’ => [
‘model’ => ‘whisper-1’
]
]);

Content-Type is not “JSON”.

Example from API dox:

curl https://api.openai.com/v1/audio/transcriptions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: multipart/form-data" \
  -F file="@/path/to/file/audio.mp3" \
  -F model="whisper-1"

Hello,

Thanks for your answer/help, I changed the content-type and now I get the answer

{
“success”: false,
“message”: “An error occurred: json_encode error: Type is not supported”
}

I changed the code to:

// Make API request to transcribe audio
$response = $client->post(‘https://api.openai.com/v1/audio/transcriptions’, [
‘headers’ => [
‘Authorization’ => “Bearer {$apiKey}”,
‘Content-Type’ => ‘multipart/form-data’,
],
‘json’ => [
‘model’ => ‘whisper-1’,
‘name’ => ‘audio_file’,
‘file’ => fopen($audioPath, ‘r’),
]
]);

I’ve already managed to run the audio transcription, but the transcription model is unsatisfactory.

Thanks for the response

You can read about whisper prompting, to improve the interpretation of the audio with not just a previous transcript to continue on, but also made up prompts to influence the audio interpretation.