Skip to content

Error using StringIO in audio transcription #243

Description

@leejarvis

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    generatorTouches generated SDK files

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions