Towards AI Can Help your Team Adopt AI: Corporate Training, Consulting, and Talent Solutions.


Generate Subtitles in any Language for YouTube Videos with Python
Latest   Machine Learning

Generate Subtitles in any Language for YouTube Videos with Python

Last Updated on December 21, 2023 by Editorial Team

Author(s): Okoh Anita

Originally published on Towards AI.

Transcribing and translating a German YouTube video into English
Image by Author

Have you ever searched for a niche topic on YouTube, say the German pension system, for example, and you realized most of the video resources are not in English but in a different language, say German, with no subtitles, or the YouTube auto-translate tool is wonky?

That happens to me more frequently than I care to admit. With all the popularity of generative AI, I can, without fear, dream of a time when all YouTube videos can be lip-synced easily to any language, and the barrier that languages pose would start to crumble. Sadly, that time is still in its infancy, and we need to find creative ways to work around it.

In terms of “working around”, I typically download the video and automate the subtitle-inputting process with Python. This involves

First, download the video of your choiceExtracting the audio from the videoTranscribe the audio and then translate it into the language of your choice. In my case, English.Create a SRT Subtitle from the translated results and saveFinally, add the subtitle back into the videoImage from Author

To translate all this into Python, we first need to install the following dependencies and libraries.

!pip install moviepy!pip install pytube!apt install imagemagick!cat /etc/ImageMagick-6/policy.xml U+007C sed… Read the full blog for free on Medium.

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI

Feedback ↓