Add AI-Powered Subtitles to Videos Easily
Learn how to quickly add AI-generated subtitles to videos using Assembly AI with just a few lines of code. Perfect for YouTube and local playback.
File
5 Lines of Python Code to Create Video Subtitles
Added on 01/29/2025
Speakers
add Add new speaker

Speaker 1: 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 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 chars per caption variable and this is going to be an integer so we can specify it to be 100 to 50. I think it's overall is 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 too 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 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 have 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.

ai AI Insights
Summary

Generate a brief summary highlighting the main points of the transcript.

Generate
Title

Generate a concise and relevant title for the transcript based on the main themes and content discussed.

Generate
Keywords

Identify and highlight the key words or phrases most relevant to the content of the transcript.

Generate
Enter your query
Sentiments

Analyze the emotional tone of the transcript to determine whether the sentiment is positive, negative, or neutral.

Generate
Quizzes

Create interactive quizzes based on the content of the transcript to test comprehension or engage users.

Generate
{{ secondsToHumanTime(time) }}
Back
Forward
{{ Math.round(speed * 100) / 100 }}x
{{ secondsToHumanTime(duration) }}
close
New speaker
Add speaker
close
Edit speaker
Save changes
close
Share Transcript