Music file size in WebGL

I’m working on a WebGL project and managed to reduce my music file to 75kB using reduced samplerate and lots of tricks. After importing it in Unity with minimal settings (ForceToMono= true, Quality=1) the imported size for WebGL is 0.9MB . So Unity managed to increase the size by more than a factor of 10. Sample rate is 44.1kHz now (original: 8kHz).

How can I get Unity to maintain the original settings or somehow reduce file size?

Thanks.

anyone? Heeeelp :wink:

Same problem here. Pretty helpless at that point if I wanna include a music track or even multiple music tracks into my webgl game. Even when they are not even that long. Audio seems a weak spot in WebGL, which is disappointing. No matter how you crunch them externally, I see no option to further reduce the file size either, instead, Unity even bloats them up. I am thinking of maybe chunking something down into smaller individual pieces and time them in Timeline, which could then be arranged differently per level or situation. Very creative solution but better than nothing I guess.
Geiler Name übrigens :smile:

Bump! Will WebGL get any propper support fow audio formats, compression and streaming??

Hi everyone,

WebGL is definitely a weak spot of the audio engine. The current format of all audio assets when baked for WebGL is MP4/AAC, so it explains the bloating you’re mentioning.

We’re painfully aware of this and we’re currently focusing our energy on the future. There are a lot of exciting things happening in the universe of web audio (audioworklets, emscripten, etc.) and I honestly hope we’ll be able to leverage them at some point. I’m unable to disclose more on that matter, for obvious legal reasons…

I wonder if maybe your audio files could be kept in an raw binary format and then manually loaded with AudioClip.Create and AudioClip.SetData. This suggests some more management code, a kind of custom soundbank maybe… On top of my mind that’s how I’d try to make happen what you’re suggesting.

I’m sorry that I can’t provide a better answer… just know that we’re a (small) bunch of passionate audio developers and that we’re striving to make the Unity audio experience better as a whole. Constructive feedback is always welcomed and if you ever encounter a bug, the best and fastest way to get it looked at is by submitting a minimal project isolating the issue here.

Cheers!

1 Like

I also encountered the same problem. My wav file was only 2mb, but the actual memory usage on safari reached 200m. May I ask if you finally solved it?

Nope. Had to go full size.
But didn’t try the method from the Unity guy, which he commented on above. Would appreciate feedback here.

So is there a way to release this memory after the audio playback has finished?

You can always manually unload the audio file with AudioClip.UnloadAudioData()

The invocation of this method can only release the memory of the audioclip(2mb), but cannot release the memory of the Web Audio(200MB). (safari test)
I tested it and found that the JS_Sound_ReleaseInstance method in Audio.js is being called, but the memory is still being occupied and not released.(Unity2021.2.13f1)

Let’s keep our conversation in your other thread :wink: