How can i add audio file in SingleSound programmatically


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.



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

// Adding menu option{
    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!

1 Like

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?


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