Last updated: May 29, 2024

<span aria-hidden="true" id="mastering-audio-sync-with-transloadits-audio-delay"></span>

# Mastering audio sync with Transloadit's audio delay

![Tyler McAllister](/assets/images/teammates/tyler.png?dpl=dpl_6nhQNS5wkVkPZWuKMzXcWrAHNJL5)

**Tyler McAllister**

Technical Writer · Trondheim, Norway · Show bio

<span aria-hidden="true" id="introducing-the-audio-delay-parameter"></span>

## Introducing the audio delay parameter

One of the more unique tools available to the [/video/merge](/docs/robots/video-merge.md) Robot is its `audio_delay` parameter, which allows you to pause your audio for a defined amount of seconds. At first, adding an audio delay to a video may seem like a very specific use case. A quick search online for the term "audio delay" will give you pages of information on how to\_fix\_ audio delay, rather than intentionally create it. However, after playing around with the[/video/merge](/docs/robots/video-merge.md) Robot for a little while, I quickly found one nifty use for the parameter that I want to share with you today 😄

<span aria-hidden="true" id="preparing-the-video-and-audio"></span>

## Preparing the video and audio

In a similar vein to my last post showing off the new[watermark parameters](/blog/2019/02/inserting-watermarks.md), I will be using a free video from[Pexels videos⁠](https://videos.pexels.com/videos/vinyl-player-855943) to take us through a quick showcase of the parameter. Additionally, we'll need some audio to get started, so I'm going to use the free music track['Hey Mercy' by Pierce Murphy⁠](https://freemusicarchive.org/music/Pierce%5FMurphy/This%5FIsnt%5FMagic%5FIt%5FIs%5FJust%5FMusic/Pierce%5FMurphy%5F-%5FThis%5FIsnt%5FMagic%5FIt%5FIs%5FJust%5FMusic-%5FA%5FDemo%5F-%5F10%5FHey%5FMercy)released on the [CC BY 4.0 license⁠](https://creativecommons.org/licenses/by/4.0/).

![/video/merge Robot](/_next/static/immutable/media/opengraph-image.2jc3fb-_kdgz5.png)

<span aria-hidden="true" id="syncing-things-up"></span>

## Syncing things up

Using the [/video/merge](/docs/robots/video-merge.md) Robot, we can merge the aforementioned video and audio files together pretty easily. Here's an example of an implementation I created to extract the video and audio files stored on my Dropbox, merge them together, and upload the final video onto YouTube.

```javascript
const { Transloadit } = require('transloadit')

const transloadit = new Transloadit({
  authKey: process.env.TRANSLOADIT_AUTH_KEY,
  authSecret: process.env.TRANSLOADIT_SECRET_KEY,
})

const options = {
  params: {
    steps: {
      dropbox_imported_video: {
        robot: '/dropbox/import',
        result: 'true',
        credentials: 'my_videos',
        path: `Videos/${process.argv[2]}`,
      },
      dropbox_imported_mp3: {
        robot: '/dropbox/import',
        result: 'true',
        credentials: 'my_videos',
        path: `Music/${process.argv[3]}`,
      },
      merged: {
        use: {
          steps: [
            {
              name: 'dropbox_imported_video',
              as: 'video',
            },
            {
              name: 'dropbox_imported_mp3',
              as: 'audio',
            },
          ],
        },
        robot: '/video/merge',
        result: 'true',
        audio_delay: 2.5,
        ffmpeg_stack: 'v3.3.3',
        preset: 'hls-1080p',
      },
      exported: {
        use: ['merged'],
        robot: '/youtube/store',
        credentials: 'youtube_auth_xxxxxxxxxx',
        title: process.argv[4],
        description: 'Using the /video/merge Robot I can merge audio and video!',
        keywords: 'music',
        category: 'education',
        visibility: 'unlisted',
      },
    },
  },
}

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

```

And here we can see the result:

Doesn't seem to fit too well, does it? This is where the `audio_delay` parameter has its time to shine. Let's add it to the [/video/merge](/docs/robots/video-merge.md) part of the implementation, like so:

```javascript
merged:{
  use: {
    steps: [
      {
        name: "dropbox_imported_video",
        as: "video"
      },
      {
        name: "dropbox_imported_mp3",
        as: "audio"
      }
    ]
  },
  robot: "/video/merge",
  result: true,
  audio_delay: 2.5,
  ffmpeg_stack: "{{stacks.ffmpeg.recommended_version}}",
  preset: "hls-1080p"
}

```

We can set the number of seconds to define when we want the audio to start playing. In our original video, it looks like the needle drops at around 2.5 seconds, so let's have our audio play from that point. After running the code again, I'm eager to take a look at the resulting video:

Hey presto! Our audio and video are synced up nicely together thanks to the `audio delay` parameter. In my opinion, this is one of the more unique parameters available to our Robots here at Transloadit. I hope this post will be able to spark some creativity, or at least help out anyone looking for that proverbial needle in the haystack: how to create — rather than fix — audio delay on a video!

[#audio-encoding-service](/blog/tags/audio-encoding-service.md)[#image-processing-service](/blog/tags/image-processing-service.md)[#video-encoding-service](/blog/tags/video-encoding-service.md)[#video-merge-bot](/blog/tags/video-merge-bot.md)[#tutorial](/blog/tags/tutorial.md)[#video-merge-robot](/blog/tags/video-merge-robot.md)

### 👩‍💻 Join 20k+ developers

Sign up for our [monthly newsletter](/newsletters.md) to receive direct links to 3 exclusive tech — and 2 product updates. No less, no more.

Your email:

Get access

## File uploading and encoding. Made simple.

Transloadit streamlines file handling for developers, trusted by brands like Coursera and The New York Times. We’re known for a reliable API, top-notch support, and a strong commitment to open source, with projects like [Uppy⁠](https://uppy.io) and [Tus⁠](https://tus.io) setting standards in file processing.

[Sign up](/c/)[Book a Demo](https://survey.typeform.com/to/kRg47Xi5)

No credit card needed · 5 GB included in the free plan

Cancel anytime
