Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Audio Music file size in WebGL

Discussion in 'Audio & Video' started by DerDicke, Mar 14, 2019.

  1. DerDicke

    DerDicke

    Joined:
    Jun 30, 2015
    Posts:
    291
    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.
     
  2. DerDicke

    DerDicke

    Joined:
    Jun 30, 2015
    Posts:
    291
    anyone? Heeeelp ;-)
     
  3. HenryTownshend

    HenryTownshend

    Joined:
    Jun 19, 2017
    Posts:
    10
    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 :D
     
    Last edited: Feb 3, 2021
  4. battou

    battou

    Joined:
    Jan 25, 2011
    Posts:
    197
    Bump! Will WebGL get any propper support fow audio formats, compression and streaming??
     
  5. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    290
    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!
     
    Last edited: Mar 23, 2023
    mgear likes this.
  6. zengjunjie59

    zengjunjie59

    Joined:
    Dec 10, 2019
    Posts:
    19
    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?
     
  7. DerDicke

    DerDicke

    Joined:
    Jun 30, 2015
    Posts:
    291
    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.
     
  8. zengjunjie59

    zengjunjie59

    Joined:
    Dec 10, 2019
    Posts:
    19
    So is there a way to release this memory after the audio playback has finished?
     
  9. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    290
    You can always manually unload the audio file with AudioClip.UnloadAudioData()
     
  10. zengjunjie59

    zengjunjie59

    Joined:
    Dec 10, 2019
    Posts:
    19
    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)
     
  11. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    290
    Let's keep our conversation in your other thread ;)