How to write a Python script for the new version of OpenAI Whisper API?

Hello everyone, recently when I use my previous Whisper code, I encounter the following error:

“You tried to access openai.Audio, but this is no longer supported in openai>=1.0.0 - see the README at GitHub - openai/openai-python: The official Python library for the OpenAI API for the API. You can run openai migrate to automatically upgrade your codebase to use the 1.0.0 interface. Alternatively, you can pin your installation to the old version, e.g. pip install openai==0.28. A detailed migration guide is available here: openai/openai-python#742.”

Afterwards, I rewrote the code as shown below. It works now, but when I use the ‘medium’ model size or larger, it crashes.
Could this be due to my computer not having a dedicated graphics card?

The code I’ve written seems to be for local use and does not utilize the paid Whisper service.
Besides that, how can I modify the code to use an API key with the Whisper program?

How can I modify my script to make it as convenient as before when I was using result = openai.Audio.transcribe(“whisper-1”, f)?

Thanks for everyone

audio_file = AudioSegment.from_file("test.mp3")

chunk_size = 60 * 1000

chunks = [audio_file[i:i+chunk_size] for i in range(0, len(audio_file), chunk_size)]

openai.api_key = "XXXXXXXXXXXXXXXX"

transcript = ""

model = whisper.load_model("large")

for i, chunk in enumerate(chunks, start=1):
    output_filename = f"temp_{i}.wav"
    chunk.export(output_filename, format="wav")
    result = model.transcribe(output_filename)
    raw_text = result["text"]
    print(f"Chunk {i}: {raw_text}")
    transcript += raw_text + '\n'
transcript = transcript.replace('\n\n', '\n')
print("Final: " + transcript)