I have a task of extracting text from a given audio file, so when I use this,
client=OpenAI(api_key=, i start having an error of
ImportError: cannot import name ‘OpenAI’ from ‘openai’
There are similar questions on this forum, so using that I solved it by upgrading the version to latest openai.
But versions 1.0.0 and above do not support the use of, audio.create_transcriptions()
which is present in my code.
So in short, it’s kind of stuck in place.
I’m relatively new to this but could really use some help
Below is the code which I’m using for the text extraction,
def transcribe_audio_openai(local_audio_path: str) → str:
try:
with open(local_audio_path, "rb") as audio_file:
whisper_response = client.Audio.create_transcription(
file=audio_file,
model="whisper-1",
prompt="Medical transcription task."
)
raw_transcription = whisper_response.get("text")
gpt_response = openai.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": f"Refine the following transcription:\n{raw_transcription}"}
]
)
refined_transcription = gpt_response["choices"][0]["message"]["content"]
return refined_transcription
except Exception as e:
raise RuntimeError(f"Failed to transcribe or refine audio: {e}")
FYI: I am using whisper-1 to extract the text and 4o-mini to enhance it