Getting 400 when trying to hit the openai's whisper API. How to resolve it?

143 views Asked by At

I am trying to use openAI's whisper API for trascribing an audio file. I wrote a simple python code for it. API documentation it requires two parameters in teh request. One of them is model. And I have used whisper-1 as model as seen below in my code. But it gives me a 400 asking for model param. I am doing this from a virtual environment in VSCode from MAC.

import os
import openai
import requests
import json

api_key = "xxxx"
url = "https://api.openai.com/v1/audio/transcriptions"
audio_file_path = "/Users/xxxx/Downloads/Test_girl_eng1.m4a"

params = {
    "model": "whisper-1",
    "file": "/Users/xxxx/Downloads/Test_girl_eng1.m4a",
    "language": "en",
    "response_format": "json",
    "temperature": 0.2,
}

files = {
    "file": ("audio.wav", open(audio_file_path, "rb")),
}

response = requests.post(url, headers={"Authorization": f"Bearer {api_key}"}, params=params)

if response.status_code == 200:
    transcription_data = response.json()
    transcribed_text = transcription_data["transcription"]
    print("Transcribed Text:")
    print(transcribed_text)
else:
    print("Error:", response.status_code)
    print(response.text)

Response:

{
    "error": {
        "message": "you must provide a model parameter",
        "type": "invalid_request_error",
        "param": null,
        "code": null
    }
}

Please help me finding whats wrong here.

0

There are 0 answers