Help on API translation script

hi

I use the script below but i have an error :
Échec de la requête : 404
{
*** “error”: {***
*** “message”: “Invalid URL (POST /v1/audio/translations)”,***
*** “type”: “invalid_request_error”,***
*** “param”: null,***
*** “code”: null***
*** }***
}

what is wrong please?

import requests
import json

# Remplacez 'your-api-key' par votre clé API OpenAI
api_key = 'MY KEY'

# Endpoint de l'API OpenAI pour les traductions audio
endpoint = 'https://api.openai.com/v1/audio/translations'

# Données de la requête
data = {
    "model": "text-davinci-003",
    "data": {
        "audio": {
            "url": "https://your-audio-file-url.mp3",  # Remplacez par l'URL de votre fichier audio
        },
        "target_language": "fr",  # Remplacez par la langue cible de la traduction
    },
}

# En-têtes de la requête
headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {api_key}',
}

# Envoi de la requête POST à l'API OpenAI
response = requests.post(endpoint, data=json.dumps(data), headers=headers)

# Vérification de la réponse
if response.status_code == 200:
    result = response.json()
    print("Traduction audio réussie :")
    print(result)
else:
    print(f"Échec de la requête : {response.status_code}")
    print(response.text)

I believe you’re using the wrong model

Should be whisper-1 instead of text-davinci-003

Exact!
But i have a new error:
Échec de la requête : 400
{
“error”: {
“message”: “1 validation error for Request\nbody → file\n field required (type=value_error.missing)”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}

Where did you find this parameter? target_language

I don’t seem to find it in the OpenAI documentation - and it seems only translating to English is currently supported (althought I may be mistaken).

https://platform.openai.com/docs/api-reference/audio/createTranslation

I don’t see target_language

Another thing you could so is convert audio to text using Whisper and then use ChatCompletions to convert from English text to French text

The only way you would get code like that is by asking an AI.

  • The only model supported is whisper-1, not “text-davinci-003”;
  • The parameter for the audio contents is "file":;
  • You must use http multipart/form, with a mime-encoded audio file;
  • The translation endpoint is only for translation TO English.
    etc.