Skip to content
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

Transcription from Bytes instead of file #143

Closed
turulix opened this issue Jan 31, 2025 · 4 comments
Closed

Transcription from Bytes instead of file #143

turulix opened this issue Jan 31, 2025 · 4 comments

Comments

@turulix
Copy link

turulix commented Jan 31, 2025

Describe the feature or improvement you're requesting

I want to create a audio_transcription without having to write the bytes to a file first

Additional context

No response

@dongri
Copy link
Owner

dongri commented Jan 31, 2025

@turulix
Copy link
Author

turulix commented Jan 31, 2025

Yes, but the current implementation requires one to provide a path to the file:

pub file: String,

which then just gets read from disk:

let form = Self::create_form(&req, "file")?;

openai-api-rs/src/v1/api.rs

Lines 787 to 806 in b763a66

let mut file = match File::open(file_path) {
Ok(file) => file,
Err(e) => {
return Err(APIError::CustomError {
message: e.to_string(),
})
}
};
let mut buffer = Vec::new();
match file.read_to_end(&mut buffer) {
Ok(_) => {}
Err(e) => {
return Err(APIError::CustomError {
message: e.to_string(),
})
}
}
let mut form =
Form::new().part("file", Part::bytes(buffer).file_name(file_path.to_string()));

Since im doing the transcription via a webserver i get the file as a byte array. Which then forces me to actually write those bytes to a file just to have the library read it into memory again making that read & write redundant and skipable

@dongri
Copy link
Owner

dongri commented Jan 31, 2025

I see, OK. I will think about how to make the modifications.

@dongri
Copy link
Owner

dongri commented Feb 1, 2025

@dongri dongri closed this as completed Feb 3, 2025
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

No branches or pull requests

2 participants