If you want to quickly add subtitles to your videos and take them from this, based on this research, now AI can learn to use digital tools like to this and few or zero shot settings when it comes to natural language processing tasks. You can do it with Assembly AI. And it's going to be just a couple of lines of code, very quick, based on your transcription that you submitted to Assembly AI.
You're going to get timed subtitles that you can upload to YouTube or use on your local computer, however you like. The first thing that you want to do is to make sure that you have the Assembly AI SDK installed and for that all you have to do is go to your terminal and write down pip install Assembly AI and that will install the Python SDK of Assembly AI. And then you want to make sure that you have a Assembly AI API key and that is free to get so just head on to assemblyai.com, create an account and you will get a free API key from Assembly AI.
And then in your Python file Just import Assembly AI as AAI and then set your Assembly AI key, the API key here. And then you just want to start a transcription job. So create a transcriber object and on that I can start the transcription job. You can either pass a video or audio file directly to Assembly AI. So the video I'm working with in this example is this one.
Can AI learn to use tools? Well maybe not physical one. But this is a 4k video and it is 1.18 gigabytes so it's going to take some time to be uploaded to Assembly AI.
Instead you can just if you're on mac you can start the QuickTime player. and then say file export as audio only and it will strip the audio of your video and then my audio is only 8.7 megabytes so it's going to go much faster. So that's why I'm going to pass the tool former m4a file to be transcribed and once the transcription is ready all I have to do is to say export subtitles srt So this will export the subtitles in the SRT format. If you want it can also export them in the VTT format. So I'll use the SRT format right now.
You don't have to pass anything to it, but if you want to specify how many characters maximum you want on each caption, you can specify charts per caption variable. And this is going to be an integer, so we can specify it to be 100 to 50. I think overall it's generally between 80 and 100. So 50 would be a bit short and 150 would be a bit long. But we don't have to specify this.
We'll just use a default value. And then I'm just going to open a file. I'll just call this subtitles.srt with write permission. And then write my subtitles in there.
and then close the file. All right let's run this and see how it goes. All right now that this is done let's go and take a look. I can open it with text editor and this is what it looks like and this would be as you can see this is timed and it will be accepted by anywhere that accepts the SRT files. You can upload it to youtube for example with your video.
Or as far as I know on the VLC player 2 you can add subtitles on top of a video that you have. And that's how you can get subtitles for your videos in just how many lines of code? One, two, three, four, five lines of code. I mean we'll just count this as one, you know, just writing it into file.
So that's it. If you have any questions make sure to leave them down below in the comment section. If you want to learn more about this functionality, you can go to the assembly.ai documentation or the SDK documentation on GitHub.
I will make sure to leave links for you in the description below. Thanks for watching and I will see you in the next video.