Audio Looping

Transloadit offers the ability to loop an audio file for as often as is required to meet a certain target duration. In the demo below, we loop the uploaded audio file until it is five minutes long.

Warning It seems your browser does not send the referer, which we need to stop people from (ab)using our demos in other websites. If you want to use the demos, please allow your browser to send its referer to us. Adding us to the whitelist of blockers usually helps.

This demo uses:

  • Our /audio/loop Robot, which loops one audio file as often as is required to match a given duration


This demo uses :original, a magic word indicating uploads that were received by Transloadit.


<body>
  <form action="/uploads" enctype="multipart/form-data" method="POST">
    <input type="file" name="my_file" multiple="multiple" />
  </form>

  <script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
  <script src="//assets.transloadit.com/js/jquery.transloadit2-v3-latest.js"></script>
  <script type="text/javascript">
  $(function() {
    $('form').transloadit({
      wait: true,
      triggerUploadOnFileSelection: true,
      params: {
        auth: {
          // Secure via: https://transloadit.com/docs/api-docs/#authentication
          key: 'YOUR_TRANSLOADIT_KEY',
        },
        // It's often better to use a `template_id` than to
        // inline encoding instructions here:
        steps: {
          mp3: {
            use: ':original',
            robot: '/audio/loop',
            result: true,
            duration: 300,
            preset: 'mp3'
          }
        }
      }
    });
  });
  </script>
</body>
<link href="https://unpkg.com/uppy/dist/uppy.min.css" rel="stylesheet">
<script src="https://unpkg.com/uppy/dist/uppy.min.js"></script>
<button id="uppy-open-modal">Select Files</button>
<script>
  const uppy = Uppy.Core({ debug: true, autoProceed: false })
    .use(Uppy.Tus10, { resume: false })
    .use(Uppy.Transloadit, {
      params: {
        auth: {
          key: 'YOUR_TRANSLOADIT_KEY',
        },
        steps: {
          mp3: {
            use: ':original',
            robot: '/audio/loop',
            result: true,
            duration: 300,
            preset: 'mp3'
          }
        }
      },
      waitForEncoding: true,
    })
    .use(Uppy.Dashboard, {
      trigger: '#uppy-open-modal',
      target: 'body'
    })
    .use(Uppy.Webcam, { target: Dashboard })
    .on('transloadit:result', (stepName, result) => {
      // use transloadit encoding result here.
      console.log('Result here ====>', stepName, result)
    })
    .run()
</script>
// npm install transloadit --save
const TransloaditClient = require('transloadit')

const transloadit = new TransloaditClient({
  authKey: 'YOUR_TRANSLOADIT_KEY',
  authSecret: 'YOUR_TRANSLOADIT_SECRET'
})

transloadit.addFile('myinput_1', './dutch-anthem.mp3')

const options = {
  params: {
    steps: {
      mp3: {
        use: ':original',
        robot: '/audio/loop',
        result: true,
        duration: 300,
        preset: 'mp3'
      }
    }
  }
}

transloadit.createAssembly(options, (err, result) => {
  if (err) {
    throw err
  }

  console.log({result})
})
// Install "transloadit/php-sdk"
// via Composer (https://getcomposer.org)
use transloadit\Transloadit;
$transloadit = new Transloadit(array(
  "key" => "YOUR_TRANSLOADIT_KEY",
  "secret" => "YOUR_TRANSLOADIT_SECRET",
));

$files = array();
array_push($files, "./dutch-anthem.mp3");

$response = $transloadit->createAssembly(array(
  "files" => $files,
  "params" => array(
    "steps" => json_decode({
      "mp3": {
        "use": ":original",
        "robot": "/audio/loop",
        "result": true,
        "duration": 300,
        "preset": "mp3"
      }
    }, true),
  ),
));
# gem install transloadit
transloadit = Transloadit.new(
  :key => "YOUR_TRANSLOADIT_KEY",
  :secret => "YOUR_TRANSLOADIT_SECRET"
)

mp3 = transloadit.step "mp3", "/audio/loop",
  :use => ":original",
  :result => true,
  :duration => 300,
  :preset => "mp3"
)

assembly = transloadit.assembly(
  :steps => [ mp3 ]
)

files = []
files.push('./dutch-anthem.mp3')

response = assembly.create! *files

until response.finished?
  sleep 1; response.reload!
end

if !response.error?
  # handle success
end
# pip install pytransloadit
from transloadit import client

tl = client.Transloadit('YOUR_TRANSLOADIT_KEY', 'YOUR_TRANSLOADIT_SECRET')
assembly = tl.new_assembly()

# Add files to upload
assembly.add_file(open('./dutch-anthem.mp3', 'rb'))

# Add instructions, e.g. resize image, or encode video
assembly.add_step('mp3', {
  'use': ':original',
  'robot': '/audio/loop',
  'result': true,
  'duration': 300,
  'preset': 'mp3'
})

# Start the Assembly
assembly_response = assembly.create(retries=5, wait=True)

print assembly_response.data.get('assembly_id')

# or
print assembly_response.data['assembly_id']
// go get gopkg.in/transloadit/go-sdk.v1
options := transloadit.DefaultConfig
options.AuthKey = "YOUR_TRANSLOADIT_KEY"
options.AuthSecret = "YOUR_TRANSLOADIT_SECRET"
client := transloadit.NewClient(options)

// Initialize new assembly
assembly := transloadit.NewAssembly()

// Add files to upload
assembly.AddFile("myinput_1", "./dutch-anthem.mp3")

// Add instructions, e.g. resize image, or encode video
assembly.AddStep("mp3", map[string]interface{}{
  "use": ":original",
  "robot": "/audio/loop",
  "result": true,
  "duration": 300,
  "preset": "mp3"
})

// Start the Assembly
info, err := client.StartAssembly(context.Background(), assembly)
if err != nil {
  panic(err)
}

// All files have now been uploaded and the assembly has started but no
// results are available yet since the conversion has not finished.
// WaitForAssembly provides functionality for polling until the assembly
// has ended.
info, err = client.WaitForAssembly(context.Background(), info)
if err != nil {
  panic(err)
}

fmt.Printf("You can view the result at: %s\n", info.Results["resize"][0].SSLURL)
// compile 'com.transloadit.sdk:transloadit:0.0.3'
import com.transloadit.sdk.Assembly;
import com.transloadit.sdk.Transloadit;
import com.transloadit.sdk.exceptions.LocalOperationException;
import com.transloadit.sdk.exceptions.RequestException;
import com.transloadit.sdk.response.AssemblyResponse;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        Transloadit transloadit = new Transloadit("YOUR_TRANSLOADIT_KEY", "YOUR_TRANSLOADIT_SECRET");
        Assembly assembly = transloadit.newAssembly();
        
        Map<String, Object> mp3StepOptions = new HashMap<>();
        mp3StepOptions.put("use", ":original");
        mp3StepOptions.put("result", true);
        mp3StepOptions.put("duration", 300);
        mp3StepOptions.put("preset", "mp3");
        assembly.addStep("mp3", "/audio/loop", mp3StepOptions);
        
        assembly.addFile(new File("./dutch-anthem.mp3"));
        
        try {
            AssemblyResponse response = assembly.save();

            // wait for assembly to finish executing.
            while (!response.isFinished()) {
                response = transloadit.getAssemblyByUrl(response.getSslUrl());
            }

            System.out.println(response.getId());
            System.out.println(response.getUrl());
            System.out.println(response.json());
        } catch (RequestException | LocalOperationException e) {
            // handle exception here
        }
    }
}
npm install transloadify -g

echo '{
  "mp3": {
    "use": ":original",
    "robot": "/audio/loop",
    "result": true,
    "duration": 300,
    "preset": "mp3"
  }
}' > ./steps.json

export TRANSLOADIT_KEY="YOUR_TRANSLOADIT_KEY"
export TRANSLOADIT_SECRET="YOUR_TRANSLOADIT_SECRET"

transloadify \
  --input ./lolcat.jpg \
  --output ./resized-lolcat.jpg \
  --steps ./steps.json
{
  "steps": {
    "mp3": {
      "use": ":original",
      "robot": "/audio/loop",
      "result": true,
      "duration": 300,
      "preset": "mp3"
    }
  }
}

So many ways to integrate

Transloadit is a service for companies with developers. As a developer, there's many ways you can put us to good use.

  • Bulk imports — Add one of our import Robots to acquire the input and encode massive libraries
  • Handling uploads — We invented tus and are experts at handling uploads
  • Front-end integration — We integrate with webbrowsers via our next-gen file uploader Uppy and SDKs for Android and iOS
  • Backend-end integration — Send us batch jobs in any server language using one of our SDKs or directly interfacing with our REST API
  • Pingbacks — Configure a notify_url to let your server receive transcoding results JSON in the transloadit POST field.

Try it out

Please try it yourself by uploading an audio file. Maximum size for all demos is 100MB.

Try it in your account

Try out this demo in your own account by pasting it into one of your Templates.

Get started for free

Sign up with GitHub or

Need help? Talk to a human