How to programmatically add audio to a youtube video

Peadar Coyle
2 min readMay 28, 2021

Our mission is to create frictionless audio experiences through coding. Video is a very important part — since video is often connected to audio.

Video creation itself is already widely accessible: There are stock videos you can use to create your content and there are audio libraries with royalty-free music, many of them free. You can even use text-to-speech voice-overs if you don’t want to narrate the content yourself.

Now, with api.audio, you can do all of that programmatically through our api. Not only is it faster and, as you will see, a lot easier, it also gives you the opportunity to integrate that functionality into your personal workflows.

Today I will show you how to create a new voice-over and background music for a Youtube video. The final product is a new version of your existing video. You can create as many of these as you want, using our script parameters to automatically create thousands of versions.

But let’s start with something simple. Feel free to explore the api.audio documentation and build your own, more complex version.

Let’s consider a real world project or use case: Imagine you’re a real estate agency and you want to sell a property in London with a video walkthrough you’ve made, and you want to make that personalized to 30 potential buyers. That way, you can highlight the features you know will be important to each potential buyer and you can address each of them by name. That’s just one of the many possibilities to use this feature; you can go all in, automating and integrating it to your system if you want.

Before you start: Get your api key

It all starts with that. Here is how to do it: https://docs.api.audio/recipes/sign-up-here

1. Import packages

For Python, install FFmpeg with

sudo apt install ffmpeg or brew install ffmpeg. Then, pip install -U pytube aflr

For JavaScript:

npm install ytdl-core fluent-ffmpeg or

yarn add ytdl-core fluent-ffmpeg

Note: Don’t use yarn and npm. Pick one :)

2. Create your speech with API.audio

Let’s create some speech!

Remember to import your API key. If you haven’t done so already, you can get one here: https://console.api.audio/register

Now, choose a speaker and adjust the speed of the voice.

3. Download a video from YouTube

Let’s download a video from Youtube!

4. Set up your video with speech

Combine the audio with your video!

5. Create your video with a voice over

Create a script for your voice over.

Paste in the url of the YouTube video you want to create a voice over for!

Check your local folder for your mp4 file!

That’s it! I hope you’ll like this feature and give it a go yourself. Any feedback is always appreciated of course.

--

--

Peadar Coyle

Cofounder of www.Aflorithmic.ai building www.api.audio a simple developer tools for adding audio to your applications