Skip to content

A more obvious example of audio to text transcription #440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kbgod
Copy link

@kbgod kbgod commented Jul 7, 2025

Problem: Unclear io.Reader Expectations for Audio Transcription
Today, I encountered an issue with the openai.AudioTranscriptionNewParams.File field, where the expected behavior of an io.Reader was not immediately obvious.

As a developer, when a function or method expects an io.Reader, I typically anticipate that only the Read method will be necessary. However, upon inspection of the library's internal code, it became clear that the io.Reader provided to this method is implicitly type-asserted to inline interfaces expecting Filename() or Name() or ContentType() methods.

This hidden dependency leads to a problem when providing a simple io.Reader created directly from bytes, such as with bytes.NewReader(audioBytes). In such cases, the OpenAI API returns an "unsupported format" error because it lacks the necessary metadata (filename and content type) to correctly process the audio.

Solution: Explicit Wrapping with openai.File
To address this, it's crucial to explicitly wrap the io.Reader using openai.File(bytes.NewReader(audioBytes), filename, contentType). This ensures that the required filename and contentType metadata are correctly associated with the reader before it's passed to the API.

This approach is particularly beneficial when audio data is downloaded over the network. It eliminates the need to create a local temporary file simply to satisfy the API's implicit requirements, streamlining the workflow and reducing disk I/O.

@kbgod kbgod requested a review from a team as a code owner July 7, 2025 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant