First off, I’d like to thank those who previously helped me resolve issues with setting up chat functionality using the OpenAI Python API on my Raspberry Pi. Your guidance was invaluable!
I’m now working on a new aspect of my project, specifically focusing on voice interactions. The goal is to transcribe audio using the whisper-1 model with the OpenAI Python library. However, I’ve run into some challenges and could use your expertise.
The Setup:
Python version: 3.11
OpenAI Python Library version: 1.43.0
Environment: Raspberry Pi
The Issue:
I’m trying to transcribe an audio file using the code snippet below:
python
Copy code
import openai
def transcribe_audio(file_path):
with open(file_path, "rb") as audio_file:
response = openai.Audio.transcriptions.create(
model="whisper-1",
file=audio_file,
response_format="json"
)
return response['text']
Unfortunately, when I run this code, I receive the following error:
kotlin
Copy code
openai.lib._old_api.APIRemovedInV1: You tried to access openai.Audio, but this is no longer supported in openai>=1.0.0
What I’ve Tried:
Updated the OpenAI Python library to the latest version.
Ensured the environment is correctly set up on the Raspberry Pi.
Successfully implemented chat functionality using GPT models.
Questions:
Has anyone else encountered this issue with audio transcription? How did you overcome it?
Is there an alternative method or a new approach for using the latest OpenAI Python library to handle audio transcriptions?
Are there any known compatibility issues or workarounds specific to using the OpenAI API on Raspberry Pi?
Once again, I appreciate all the help and guidance this community has provided. Any suggestions or advice would be greatly appreciated as I continue to work on this project.
I hope this message finds you well. I have been working on implementing audio transcription using the OpenAI API in my project, but I have encountered persistent issues despite following the documentation and recommendations.
Context:
I am using the latest OpenAI Python package (version 1.43.0) in a virtual environment on my Raspberry Pi. My goal is to record audio using the sounddevice library, save it as a .wav file, and then transcribe it using OpenAI’s Whisper model (whisper-1). Additionally, I plan to integrate this with a chatbot using the gpt-4o-mini model for interactive voice communication.
Steps Taken:
Environment Setup:
Created a virtual environment (newenv) and activated it.
Installed the necessary packages: openai, sounddevice, numpy, and wavio.
Script Overview:
Recorded audio and saved it as output.wav.
Attempted to transcribe the recorded audio using the openai.Audio.transcribe method.
Code Example: Here’s a simplified version of my script:
python
Copy code
import openai
import sounddevice as sd
import numpy as np
import wavio
# Set your API key
openai.api_key = "my_actual_api_key"
def record_audio(filename, duration=5, fs=44100):
print("Recording...")
recording = sd.rec(int(duration * fs), samplerate=fs, channels=2)
sd.wait() # Wait until recording is finished
wavio.write(filename, recording, fs, sampwidth=2)
print("Recording complete.")
def transcribe_audio(audio_file):
try:
with open(audio_file, "rb") as audio:
response = openai.Audio.transcribe(
model="whisper-1",
file=audio,
response_format="text"
)
return response['text']
except Exception as e:
print(f"An error occurred during transcription: {e}")
return None
def main():
audio_file = "output.wav"
record_audio(audio_file)
transcription = transcribe_audio(audio_file)
if transcription:
print(f"Transcription: {transcription}")
if __name__ == "__main__":
main()
Issue:
Upon running the script, the transcription step consistently fails with the following error message:
vbnet
Copy code
An error occurred during transcription:
You tried to access openai.Audio, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python 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: https://github.com/openai/openai-python/discussions/742
What I’ve Tried:
Verified that the openai package is indeed the latest version (1.43.0).
Ensured that the script is using the openai.Audio.transcribe method as per the latest documentation.
Attempted reinstalling the openai package, but the issue persists.
Request for Assistance:
Support Team: Could you please confirm whether the openai.Audio.transcribe method is the correct approach in the current version of the OpenAI Python library? If not, what would be the recommended method for transcription using the Whisper model (whisper-1)?
Community Forum: Has anyone successfully implemented a similar feature using the latest version of the OpenAI API? If so, could you share the working setup or any additional steps you took to resolve similar issues?
I appreciate your time and assistance in resolving this issue, and I’m eager to continue working with OpenAI’s powerful tools.
In the current Python module, you cannot use the openai.Audio.transcribe method to use Whisper.
As mentioned in the official API documentation, you need to use: