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

whisperfile server: convert files without ffmpeg #568

Merged
merged 2 commits into from
Sep 28, 2024

Conversation

cjpais
Copy link
Collaborator

@cjpais cjpais commented Sep 27, 2024

This PR allows the whisperfile server to convert .wav, .mp3, .flac, and .ogg into the appropriate .wav file for whisper (16-bit 16000Hz) without any dependency on ffmpeg.

The ffmpeg support still remains under the --convert flag.

The main change here is giving read_wav a file instead of a buffer. Before it was given a buffer when run through the server, and a filename when run through the cli. Now it is unified to always use a filename.

In addition is_wav_buffer was removed, as the codepath is dead with the changes to use a filename throughout. This function was always expecting a buffer, but was receiving both filenames and buffers.

Copy link
Collaborator

@jart jart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this. Several people have requested this feature. read_wav() isn't ready to be used in this manner, but I can make it ready after merging this. I anticipate that it won't work if concurrent requests are sent to the server until I get rid of the global variable in common.cpp. This will obviously be fixed before the next release. So please don't publish any whisperfiles until we've had a chance to fix that.

@jart jart merged commit 7517a5f into Mozilla-Ocho:main Sep 28, 2024
2 checks passed
jart added a commit that referenced this pull request Sep 28, 2024
We now have a new function slurp_audio_file() which replaces read_wav().
This function has simpler code, and allows us to avoid a temporary file.

See #568
{
fprintf(stderr, "error: failed to read WAV file\n");
const std::string error_resp = "{\"error\":\"failed to read WAV file\"}";
res.set_content(error_resp, "application/json");
return;
}
}
// remove temp file
std::remove(temp_filename.c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function you want here is unlink().

jart added a commit that referenced this pull request Sep 28, 2024
We now have a new function slurp_audio_file() which replaces read_wav().
This function has simpler code, and allows us to avoid a temporary file.

See #568
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.

2 participants