Assume that, the API Key correctly used here. For privacy issues, replaced the API Key with paste your code here. I’m trying this below code, in Streamlit. My motive is to read the audio file and show the transcript on the app. While doing that, I got below error.
import streamlit as st
import os
import openai
os.environ['OPENAI_API_KEY'] = 'paste your code here'
openai.api_key = os.environ['OPENAI_API_KEY']
st.title('OpenAIs Whisper')
# Upload audio file
audio_file = st.file_uploader("Upload audio file", type=['wav', 'mp3', 'ogg'])
# Load audio file
if audio_file is not None:
audio_bytes = audio_file.read()
st.audio(audio_bytes, format='audio/ogg')
# Process audio file in Whisper OpenAI API
if st.button('Process audio file'):
# print the audio file format
st.write(audio_file.type)
transcript = openai.Audio.transcribe("whisper-1", audio_file)
st.write(transcript)
The above code returns the error as:
Traceback (most recent call last):
File "/home/harima/Desktop/whisper ai test/env/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script
exec(code, module.__dict__)
File "/home/harima/Desktop/whisper ai test/test_whisper.py", line 25, in <module>
transcript = openai.Audio.transcribe("whisper-1", audio_file)
File "/home/harima/Desktop/whisper ai test/env/lib/python3.10/site-packages/openai/api_resources/audio.py", line 65, in transcribe
response, _, api_key = requestor.request("post", url, files=files, params=data)
File "/home/harima/Desktop/whisper ai test/env/lib/python3.10/site-packages/openai/api_requestor.py", line 230, in request
resp, got_stream = self._interpret_response(result, stream)
File "/home/harima/Desktop/whisper ai test/env/lib/python3.10/site-packages/openai/api_requestor.py", line 624, in _interpret_response
self._interpret_response_line(
File "/home/harima/Desktop/whisper ai test/env/lib/python3.10/site-packages/openai/api_requestor.py", line 687, in _interpret_response_line
raise self.handle_error_response(
openai.error.InvalidRequestError: Invalid file format. Supported formats: ['m4a', 'mp3', 'webm', 'mp4', 'mpga', 'wav', 'mpeg']