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’
]
]);
_j
September 6, 2023, 10:55pm
2
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
_j
September 8, 2023, 2:39pm
5
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.
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Whisper prompting guide\n",
"\n",
"OpenAI's audio transcription API has an optional parameter called `prompt`.\n",
"\n",
"The prompt is intended to help stitch together multiple audio segments. By submitting the prior segment's transcript via the prompt, the Whisper model can use that context to better understand the speech and maintain a consistent writing style.\n",
"\n",
"However, prompts do not need to be genuine transcripts from prior audio segments. _Fictitious_ prompts can be submitted to steer the model to use particular spellings or styles.\n",
"\n",
"This notebook shares two techniques for using fictitious prompts to steer the model outputs:\n",
"\n",
"- **Transcript generation**: GPT can convert instructions into fictitious transcripts for Whisper to emulate. \n",
"- **Spelling guide**: A spelling guide can tell the model how to spell names of people, products, companies, etc.\n",
"\n",
This file has been truncated. show original