# Query: total length of all used audio assets

**URL:** https://qa.fmod.com/t/query-total-length-of-all-used-audio-assets/14254
**Category:** FMOD Studio
**Created:** [December 13, 2018, 8:46am UTC](https://qa.fmod.com/t/query-total-length-of-all-used-audio-assets/14254 "2018-12-13T08:46:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Skaven252](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/skaven252/32/63_2.png) [@Skaven252](https://qa.fmod.com/u/Skaven252)
#### Post date: [December 13, 2018, 8:46am UTC](https://qa.fmod.com/t/query-total-length-of-all-used-audio-assets/14254/1 "2018-12-13T08:46:42Z")

</div>

As a part of our game project’s certification for Sony they want to know how much (in total length) of which audio codec(s) are used in the game’s assets.

Is there a way to query the Asset Bin so that you could get the total length of all the used (and only used) audio assets in the project?

Thanks!

---

<div class="post-metadata">

### Author: ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)
#### Post date: [December 14, 2018, 1:17am UTC](https://qa.fmod.com/t/query-total-length-of-all-used-audio-assets/14254/2 "2018-12-14T01:17:34Z")

</div>

Hi Peter,

You can use the following code to get the length of all used audio files in your FMOD Studio project.

```
    var allAssets = studio.project.model.AudioFile.findInstances();
    var totalLength = 0.00;

    allAssets.forEach(function (asset) {
        // All assets have an empty array for sounds, 
        // so use sounds.length to see if it's empty or not

        if(asset.sounds.length) {
            totalLength += asset.length;
        }
    });

    alert("Total length of all used assets:\n\n " + totalLength + " seconds\n\n " + totalLength/60 + " minutes\n\n " + (totalLength/60)/60 + " hours");

```

We haven’t heard of this requirement from Sony before. Is this a new requirement?

Thanks,  
Richard

---

<div class="post-metadata">

### Author: ![Skaven252](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/skaven252/32/63_2.png) [@Skaven252](https://qa.fmod.com/u/Skaven252)
#### Post date: [December 14, 2018, 8:47am UTC](https://qa.fmod.com/t/query-total-length-of-all-used-audio-assets/14254/3 "2018-12-14T08:47:55Z")

</div>

Thank you so much Richard for providing a script!

Does this script check that the asset is used (ie if you use the “NOT #unused” query)? I’m not a script programmer so I can’t tell if I can see that part in the syntax. Or does it start checking through the Events rather than the Asset Bin? Does it then check if the event is assigned to a bank?

> We haven’t heard of this requirement from Sony before. Is this a new requirement?

The request came to us from Sony Japan during the certification of a game project. And it came from Sony Japan only, the others did not ask this. The form asked to specify how many minutes of each codec is used in the game’s assets. We use ATRAC9 on all assets on the PS4 so that simplified the query.

---

<div class="post-metadata">

### Author: ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)
#### Post date: [December 16, 2018, 11:38pm UTC](https://qa.fmod.com/t/query-total-length-of-all-used-audio-assets/14254/4 "2018-12-16T23:38:32Z")

</div>

Hi Peter,

Yes, I can confirm this only checks if the audio asset is used (not tagged with #unused). In an audio file’s properties `asset.sounds` is an array that contains all the instruments this audio file is used in. `asset.sounds.length` will check to make sure it is more than 0.

Thank you for providing details about the certification. I will pass this information onto our API team.

Thanks,  
Richard
