# How can i add audio file in SingleSound programmatically

**URL:** <https://qa.fmod.com/t/how-can-i-add-audio-file-in-singlesound-programmatically/19671>\
**Category:** FMOD Studio\
**Created:** [December 22, 2022, 6:22am UTC](https://qa.fmod.com/t/how-can-i-add-audio-file-in-singlesound-programmatically/19671 "2022-12-22T06:22:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maulikkaloliya](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@maulikkaloliya](https://qa.fmod.com/u/maulikkaloliya)\
**Post date:** [December 22, 2022, 6:22am UTC](https://qa.fmod.com/t/how-can-i-add-audio-file-in-singlesound-programmatically/19671/1 "2022-12-22T06:22:09Z")

</div>

Hello

I wanted to add an audio file from Audio Bin to SingleSound programmatically , I wanted to select multiple sound from specific path from Audio Bin and wanted to assign that sounds in different different SingleSounds placed on timeline  
for example path of audio is  
**Car/Engine1** contains 5 audio files which I want to get all file programmatically and assign to SingleSounds.

Thanks.

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [December 23, 2022, 5:03am UTC](https://qa.fmod.com/t/how-can-i-add-audio-file-in-singlesound-programmatically/19671/2 "2022-12-23T05:03:43Z")

</div>

Hi,

Here is the code to assign a selection of audio files to instruments in an event.

> **assignAudioFiles**
>
> ```auto
> // Adding menu option
> studio.menu.addMenuItem({
> name: "Add Audio Files",
> execute: function() {assignAudioFiles();}
> })
> 
> function assignAudioFiles() {
> // Find the event we want to add the audio files to
> var eventPath = studio.system.getText("Event Path: ", "path");
> var event = studio.project.lookup(eventPath);
> 
> // Selection of audio files to be added to the event
> var audioFiles = studio.window.browserSelection();
> 
> // Find the array of instruments currently on the audio track
> // Add another `.getText` if you would like to be able to assign this to different tracks
> var track = event.groupTracks[0];
> 
> // Retrieve the instruments from the track
> var instruments = track.modules;
> 
> // Error checking
> if (instruments.length > audioFiles.length || audioFiles.length > instruments.length) {
> alert("Incompatible amount selected.");
> }
> 
> for (i = 0; i < instruments.length; i++) {
> instruments[i].audioFile = audioFiles[i];
> }
> 
> alert("Assigned all the audio files");
> }
> 
> ```

Keep in mind, this will just assign the audio files in the order they are listed in the audio bin to the order of the instruments as they are in the audio track. If you would like more control over those factors you can expand the code.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![maulikkaloliya](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@maulikkaloliya](https://qa.fmod.com/u/maulikkaloliya)\
**Post date:** [December 23, 2022, 10:33am UTC](https://qa.fmod.com/t/how-can-i-add-audio-file-in-singlesound-programmatically/19671/3 "2022-12-23T10:33:18Z")

</div>

Thanks for the fast response this helped a lot

another thing can I get a list of all audio files under a folder by giving a folder path rather than using selection?

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [December 27, 2022, 11:15pm UTC](https://qa.fmod.com/t/how-can-i-add-audio-file-in-singlesound-programmatically/19671/4 "2022-12-27T23:15:20Z")

</div>

Hi,

Unfortunately, it currently isn’t possible to get a list of assets within a folder.
