Hello,
According to the documentation for OpenAI::Resources::Audio::Transcriptions#create, the file parameter accepts StringIO. However, I'm unable to get this to work (similarly, it says it also accepts a String, but I can't get that to work either).
Here's an example:
require "openai"
file = File.open(ARGV[0])
stringio = StringIO.new(File.binread(ARGV[0]), "rb")
client = OpenAI::Client.new
transcription = client.audio.transcriptions.create(model: "gpt-4o-transcribe", file: stringio)
puts transcription.text
It works OK for the file object, but not the stringio object, which raises the following error:
{:url=>"https://api.openai.com/v1/audio/transcriptions", :status=>400, :body=>{:error=>{:message=>"Unsupported file format", :type=>"invalid_request_error", :param=>"file", :code=>"unsupported_value"}}} (OpenAI::Errors::BadRequestError)
Am I missing something or should this work?
The file I'm using is the wav sample here: https://www.kaggle.com/datasets/pavanelisetty/sample-audio-files-for-speech-recognition
Thank you
Hello,
According to the documentation for
OpenAI::Resources::Audio::Transcriptions#create, thefileparameter acceptsStringIO. However, I'm unable to get this to work (similarly, it says it also accepts aString, but I can't get that to work either).Here's an example:
It works OK for the
fileobject, but not thestringioobject, which raises the following error:Am I missing something or should this work?
The file I'm using is the wav sample here: https://www.kaggle.com/datasets/pavanelisetty/sample-audio-files-for-speech-recognition
Thank you