DEV Community

Cover image for Create automatic blog posts from videos
Karina Kato
Karina Kato

Posted on

Create automatic blog posts from videos

Blog Post Project

Overview of My Submission

This tutorial will teach you how to create blog posts automatically from videos. If you are a content creator, you may find this very useful to speed up the process of writing new posts using just your own video tutorials.

Submission Category:

Analytics Ambassadors

Link to Code on GitHub

Automatic Blog Post

built with Python3

Automatic blog post is a Python project created to generate automatically blog posts from videos.

drawing

The final blog post consists of 5 main components: title, summary, image, text and keywords. The image above represents how this architecture works. As you can see, this is a machine learning project with natural language processing.

First, we need to process the video to extract the audio. Using the DeepGram API we can do the speech to text. Later, we split the text into paragraphs. For that, we are analyzing the pause between the words to find if the sentences belong to the same paragraph or if it’s a new one.

Then, we use some pre-trained machine learning models to create the text keywords and summary. We also get the video thumbnail and name, which will be our blog post image and title, respectively.

How can I use it?

The…

Additional Resources / Info

Architecture

My Deepgram Use-Case

The final blog post consists of 5 main components: title, summary, image, text and keywords. The image above represents how this architecture works. As you can see, this is a machine learning project with natural language processing.

First, we need to process the video to extract the audio. Using the DeepGram API we can do the speech to text. Later, we split the text into paragraphs. For that, we are analyzing the pause between the words to find if the sentences belong to the same paragraph or if it’s a new one.

Then, we use some pre-trained machine learning models to create the text keywords and summary. We also get the video thumbnail and name, which will be our blog post image and title, respectively.

Getting Started

The first step to run the project is to create a DeepGram account. After that, you can generate an API key. On this page, just click on the button Create a New API Key. You'll have to choose a name for the key, set permission and set the expiration date.

Image description

After you click Create Key button, a new key will be created and it's important that you keep it safe.

To run the code, you’ll need Python installed. My suggestion is to use Anaconda, which is an open-source Python distribution platform.

I also recommend that you create a new environment specifically for this project. Check the official tutorial to learn how to download Conda and set up a virtual environment: Conda Getting Started

To install the Python packages, just clone the project and run the following command:

pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Then, simply run the command:

python generate_blog_post.py --deepgram <api_key> --video <youtube_url>
Enter fullscreen mode Exit fullscreen mode

Note: This is a demonstration tutorial, if you plan to use this in production, I recommend that you use a Key Vault to store the DeepGram API Key.

After a couple of minutes, you'll see the blog post markdown file in your output directory!

Dive into Details

The code:

  1. Downloads the audio from the specified video URL
  2. Downloads the image from the thumbnail
  3. Crops the black border of the image
  4. Saves the processed image
  5. Generates the text from the audio using DeepGram API
  6. Process the text to fix the punctuation
  7. Splits the text into new paragraphs using the median pause between words and the punctuation as a heuristic
  8. Stores the text
  9. Gets keywords from the text using KeyBERT
  10. Gets summary using pretrained Hugging Face DistilBART
  11. Creates a markdown template
  12. Fill the markdown template with title, image, summary, keywords and text
  13. Saves the markdown in the output directory

Post-processing

If you need some text post-processing, you can use the edit_blog_post module. This can be useful if your video has some domain-specific words. For example, the abbreviation "ASR" (automatic speech recognition) was captured as "As r". So, in the process_dictionary.json file which you will need to put your key-value pair "As r": "ASR".
The process_dictionary.json looks like this:

{
"As r": "ASR",
"Ai": "AI",
"Apis": "APIs"
}

Then, you can use the following command to automatically replace those words. Don't worry, because it will reuse the previous processing. So, it will not download the audio or try to transcript it again.

python edit_blog_post.py --video <youtube_url>
Enter fullscreen mode Exit fullscreen mode

Well, now your post is ready and saved in the same path!

Conclusion

Now that everything is settled. Let’s test it. For demonstration purposes, we will be using the DeepGram video tutorial on Youtube.

What is DeepGram?

The final blog post:


What is Deepgram?

#aispeechplatform #voicedata #accuraterealtimetranscription

Most automatic speech recognition services or ASR are built on technology that's over fifty years old . The old tech is fine for short call and response audio, but it just doesn't work for conversational audio . We built an end to end deep learning neural network that delivers actually usable transcriptions that get even better over time at lightning speed .

What is DeepGram

Voice enabled experiences are a big deal in business these days. For a good experience, you need a foundation of real time accurate transcription. But most automatic speech recognition services or ASR are built on technology that's over fifty years old.

Yep, even these guys. The old tech is fine for short call and response audio. Alexa, what's the weather today? But it just doesn't work for conversational audio. I'm having a problem with my super user service. This is what's happening. In order to make real use out of voice data, transcription needs to be accurate, fast, cost effective, scalable. With the old tech, you can maybe get one or two of these requirements. But no matter how hard they try, they just can't adapt it to give you all four. So we reinvented it. Hi, we're Deepgram. We built an end to end deep learning neural network. A what? Sorry, an AI speech platform that delivers actually usable transcriptions that get even better over time at lightning speed. Without how hardware costs or high transcription costs. And because we're better faster and cheaper, guess what. We're also more scalable.

So if you've avoided building that great voice feature because you lack the right APIs. Good news, it's time to get to work. Triple espresso, please, what could you do with accurate real time transcription? Oh, just off the top of our heads, You could create conversational ai. Virtual assistance voice analytics agent enable, compliance improvement better customer experience. Just to name a few. We're here to help you go big. If you don't know where to start, don't worry. In addition to providing the best technology stack, Deepgram makes an excellent partner. We know the world is constantly changing. And your audio and transcription needs will two. Will be with you every step of the way from labeling your data to training custom AI models to deployment on prem or in the cloud. To ensure your transcription foundation is powering the experience that actually delight your customers.

So if you're ready to stop chugging along on less than ideal solutions and start building the great voice product, we're ready to help make it happen Deepgram.


Thank you for reading this. Feel free to leave a comment. I hope it was helpful. Let's share some knowledge! See you in the next post! :)

Discussion (16)

Collapse
thomasbnt profile image
Thomas Bnt

Shocked

Well presented, I like the tool!

Collapse
karinakato profile image
Karina Kato Author

Thanks, Thomas! 😄

Collapse
sewvandiii profile image
Sewvandi Promodya Wickramasinghe

This is great! Very thoughtful!

Collapse
karinakato profile image
Karina Kato Author

Thanks, Sewvandi! 😁

Collapse
timhuang profile image
Timothy Huang

Amazing! A useful tool for generating post from video. Thanks for sharing.

Collapse
karinakato profile image
Karina Kato Author

Thanks, Timothy! 😀

Collapse
dhrvjha profile image
Dhruv Kumar Jha

Wooww

Collapse
karinakato profile image
Karina Kato Author

😁

Collapse
ben profile image
Ben Halpern

Wow

Collapse
karinakato profile image
Karina Kato Author

😁

Collapse
connectpritam profile image
Pritam Mullick

Will this work for languages other than English

Collapse
karinakato profile image
Karina Kato Author

Hi, Pritam. Not yet, but I intend to make a v2 can be used in other languages 🙂

Collapse
imkarthikeyan profile image
Karthikeyan

This is awesome. Nice work

Collapse
karinakato profile image
Karina Kato Author

Thanks, Karthikeyan! 😃

Collapse
moose_said profile image
Mostafa Said

This is super cool project! I was working on the same thing to add it as a new feature in one of my projects too. Great work here and good luck :)

Collapse
karinakato profile image
Karina Kato Author

Thanks, Mostafa! 🚀