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

Audio files inflate in size after loading in Gradio #3842

Closed
1 task done
sanchit-gandhi opened this issue Apr 13, 2023 · 2 comments · Fixed by #4178
Closed
1 task done

Audio files inflate in size after loading in Gradio #3842

sanchit-gandhi opened this issue Apr 13, 2023 · 2 comments · Fixed by #4178
Assignees
Labels
bug Something isn't working
Milestone

Comments

@sanchit-gandhi
Copy link

Describe the bug

Given an audio file audio.mp3, when we check the size of the file on the system, we get a file size of 2.9MB. Loading the same audio file through Gradio and checking the file size, we get a file size of 84.7MB (29x increase).

This Space demonstrates with a test file audio.mp3 (see cached examples): https://huggingface.co/spaces/sanchit-gandhi/gradio-audio-file-test

In both cases, we're computing the file size in the same way: https://huggingface.co/spaces/sanchit-gandhi/gradio-audio-file-test/blob/870f302c249f1d685648341d79f3561a1e53a71a/app.py#L7

Should there be a 29x inflation in file size after loading? This seems extreme no?

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

Refer to https://huggingface.co/spaces/sanchit-gandhi/gradio-audio-file-test

Screenshot

Screenshot 2023-04-13 at 15 37 39

Logs

N/A

System Info

See https://huggingface.co/spaces/sanchit-gandhi/gradio-audio-file-test/blob/main/README.md

Severity

annoying

@freddyaboulton
Copy link
Collaborator

I think the problem is that gradio will convert all audio files to wav, which will increase the size as wav are lossless:

Very simple repro of the issue:

image

One thing we can do is add a file_format parameter to the Audio class to control the format that the base64 data gets converted to.

In the case of the audio file in this example, that will still increase the file size but by 2x as opposed to 30x

image

However, when I tried the same approach with other mp3 files, the new files would be the same size or smaller

Case 1:
image

Case 2:
image

@sanchit-gandhi Do you have other large mp3 files on hand we can test with?

@abidlabs
Copy link
Member

One thing we can do is add a file_format parameter to the Audio class to control the format that the base64 data gets converted to.

SGTM. We have a similar format parameter in the Video component. Maybe let's use format here too for consistency?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment