OpenAI Whisper- Send Bytes (python) instead of filename

Hi All,

I also had this problem and managed to find a solution. I was using pydub to load and edit audio segments and then wanted to send a pydub audio segment directly to whisper without having to create a temporary file. The following approach worked: basically create BytesIO buffer, encode the audio into it in a supported format and then pass it to whisper:

import openai
from pydub import AudioSegment

fname = "file.mp3"
audio = AudioSegment.from_file(fname, format="mp3")
# only use first 5sec
audio = audio[:5000]

buffer = io.BytesIO()
# you need to set the name with the extension
buffer.name = fname
audio.export(buffer, format="mp3")

transcript = openai.Audio.transcribe("whisper-1", buffer)
14 Likes