Audio is one of the most important parts of any video production, making users engage with the content and the message. Audio elements allow you to add sound and music to your video and works in a quite similar way than Video elements.

If an audio element is added to a scene, the audio is contained in the scene and will be cut when moving to the next scene. On the other hand if an Audio element is added directly as a movie element, the audio is played over the scenes. Now we will see this in the next 2 examples.

Adding sound to a scene

In this first example we will create a video with 2 scenes. In the first scene we will add some thunder sound effects to a muted video, and we will leave the second scene without audio.

{
    "resolution": "full-hd",
    "quality": "high",
    "scenes": [
        {
            "comment": "Scene #1",
            "elements": [
                {
                    "type": "video",
                    "src": "https://assets.json2video.com/assets/videos/thunder-storm-02.mp4"
                },
                {
                    "type": "audio",
                    "src": "https://assets.json2video.com/assets/audios/thunder-01.mp3"
                },
                {
                    "type": "audio",
                    "src": "https://assets.json2video.com/assets/audios/thunder-02.mp3",
                    "start": 2.5
                },
                {
                    "type": "audio",
                    "src": "https://assets.json2video.com/assets/audios/thunder-01.mp3",
                    "start": 5.2
                },
                {
                    "type": "audio",
                    "src": "https://assets.json2video.com/assets/audios/thunder-02.mp3",
                    "start": 8
                }
            ],
            "duration": 10
        },
        {
            "comment": "Scene #2",
            "elements": [
                {
                    "type": "video",
                    "src": "https://assets.json2video.com/assets/videos/rain-01.mp4"
                }
            ],
            "duration": 10
        }
    ]
}

As expected, when the video switches from scene #1 to scene #2, audio gets muted as scene #2 has no audio.

Adding sound to a movie with multiple scenes

In this second example, we will add the sound effects as movie elements instead of scene #1 elements:

{
    "resolution": "full-hd",
    "quality": "high",
    "scenes": [
        {
            "comment": "Scene #1",
            "elements": [
                {
                    "type": "video",
                    "src": "https://assets.json2video.com/assets/videos/thunder-storm-02.mp4"
                }
            ],
            "duration": 10
        },
        {
            "comment": "Scene #2",
            "elements": [
                {
                    "type": "video",
                    "src": "https://assets.json2video.com/assets/videos/rain-01.mp4"
                }
            ],
            "duration": 10
        }
    ],
    "elements": [
        {
            "type": "audio",
            "src": "https://assets.json2video.com/assets/audios/thunder-01.mp3"
        },
        {
            "type": "audio",
            "src": "https://assets.json2video.com/assets/audios/thunder-02.mp3",
            "start": 2.5
        },
        {
            "type": "audio",
            "src": "https://assets.json2video.com/assets/audios/thunder-01.mp3",
            "start": 5.2
        },
        {
            "type": "audio",
            "src": "https://assets.json2video.com/assets/audios/thunder-02.mp3",
            "start": 8
        }
    ]
}

The resulting video has audio over the 2 scenes, as thunder sound effects extend longer than the scene #1.

Adjusting the music to the length of the movie

It's a common scenario that you want to add a music soundtrack that is longer than the movie itself. In this situations, the music (or any audio) can be adjusted to the length of the movie and also add a final fade out so music does not end abruptly.

The easiest way to do this is to set the duration of the audio element to -2 (sets the length to the duration of the movie) and the fade-out to the number of seconds to fade out the music.

In this example, we will force the audio to match the length of the movie and add a fade out at the end of the movie:

{
    "id": "q8azbhvg",
    "comment": "Audio example",
    "width": 1920,
    "height": 1080,
    "draft": false,
    "scenes": [
        {
            "id": "qlhg1xpe",
            "comment": "Intro bumper",
            "elements": [
                {
                    "id": "q9fwzjpg",
                    "type": "component",
                    "component": "basic/000",
                    "settings": {
                        "headline": {
                            "text": [
                                "Example of adjusted music"
                            ],
                            "color": "white",
                            "font-family": "Roboto Mono",
                            "font-weight": "400",
                            "letter-spacing": "0.5px"
                        },
                        "body": {
                            "color": "white",
                            "text": [
                                ""
                            ],
                            "font-family": "Roboto Mono",
                            "font-weight": "400"
                        },
                        "card": {
                            "vertical-align": "center",
                            "text-align": "center",
                            "padding": "2vw"
                        }
                    },
                    "x": 0,
                    "y": 0,
                    "duration": 5,
                    "comment": "Simple card",
                    "position": "custom",
                    "width": -1,
                    "height": -1
                }
            ],
            "background-color": "#000000"
        },
        {
            "id": "qk1jl7du",
            "comment": "Snowy landscape",
            "elements": [
                {
                    "id": "qh6ersxf",
                    "type": "video",
                    "src": "https://assets.json2video.com/assets/videos/landscape-01.mp4",
                    "fade-out": 2
                }
            ]
        }
    ],
    "elements": [
        {
            "id": "qu658a67",
            "type": "audio",
            "src": "https://assets.json2video.com/assets/audios/advertime.mp3",
            "duration": -2,
            "fade-out": 3
        }
    ],
    "resolution": "custom"
}

The resulting video is (turn volume on):

Balancing music and voice volume

When you want to add music and narration to a video, you typically need to adjust the volume so that the voice can be heard clearly. The best option is to keep the voice at its original volume and reduce the volume of the music.

For this purpose, the API provides the volume property in elements of type video, audio and voice. This property adjusts the volume gain.

This means it is a relative volume value compared to the original volume:

When you are combining music and voice, the recommended option in these cases is:

Depending on the type of music, you may need to adjust the value of 0.3, but you can start testing from that value.