Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Automating Insertion of External Sound Clips

  • Automating Insertion of External Sound Clips

    Posted by Gordon Grant on May 14, 2020 at 8:38 am

    Hi

    Is there a simple script to insert external audio files at specific time points in the compostion?

    I have 50 short audio files that last for 5 seconds each. I want to play them with a 5 second gap between each one. So the audio output would look like this:

    0-5secs : 01.mp3
    5-10secs : <>
    10-15secs : 02.mp3
    15-20secs : <>
    20-25secs : 03.mp3
    etc

    The filenames are listed in a TXT file, with each filename on a new line.

    (This is linked to similar question that I asked last week, but I can’t work out how to amend that script to achieve this requirement: https://forums.creativecow.net/docs/forums/post.php?forumid=227&postid=44792)

    Thanks!

    Here is the script that Andrei Popa provided for last week's question...

    var myTextProp = app.project.activeItem.selectedLayers[0]("ADBE Text Properties")("ADBE Text Document");
    var myFile = File.openDialog("Select your source file");
    if(myFile != null&&myFile.open("r")){
    var myString = myFile.read();
    myFile.close();
    }

    var arrayOfWords = myString.split('\n');

    for(var i = 0; i &lt; arrayOfWords.length;i++){
    myTextProp.setValueAtTime(5*i,arrayOfWords[i])
    }

    Gordon Grant replied 6 years, 3 months ago 2 Members · 3 Replies
  • 3 Replies
  • Andrei Popa

    May 14, 2020 at 3:35 pm

    Haven’t test this but it should work. Run this with the target composition opened. Also, the sound files must be in the same folder as your text file.


    var myFile = File.openDialog("Select your source file");
    if (myFile != null && myFile.open("r")) {
    var myString = myFile.read();
    myFile.close();
    }

    var arrayOfFileNames = myString.split("\n");

    for (var i = 0; i < arrayOfFileNames.length; i++) {
    mySoundLayer = addFileToProject(new File(myFile.path + "/" + arrayOfFileNames[i]), aoo.project.activeItem);
    mySoundLayer.startTime = i * 10;
    }

    function addFileToProject(myFile, myComp) {
    var myImportOptions = new ImportOptions();
    myImportOptions.file = myFile;
    var fileAsItem = app.project.importFile(myImportOptions);
    if (myComp != null) {
    return myComp.layers.add(fileAsItem);
    }
    return fileAsItem;
    }

    Andrei
    My Envato portfolio.

  • Andrei Popa

    May 14, 2020 at 3:35 pm

    I had a typo


    var myFile = File.openDialog("Select your source file");
    if (myFile != null && myFile.open("r")) {
    var myString = myFile.read();
    myFile.close();
    }

    var arrayOfFileNames = myString.split("\n");

    for (var i = 0; i < arrayOfFileNames.length; i++) {
    mySoundLayer = addFileToProject(new File(myFile.path + "/" + arrayOfFileNames[i]), app.project.activeItem);
    mySoundLayer.startTime = i * 10;
    }

    function addFileToProject(myFile, myComp) {
    var myImportOptions = new ImportOptions();
    myImportOptions.file = myFile;
    var fileAsItem = app.project.importFile(myImportOptions);
    if (myComp != null) {
    return myComp.layers.add(fileAsItem);
    }
    return fileAsItem;
    }

    Andrei
    My Envato portfolio.

  • Gordon Grant

    May 14, 2020 at 5:11 pm

    Again sir, that is genius! Thank you very much in deed!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy