Building a YouTube AI assistant for content creators with Python

**Using Assembly AI to Generate Time Stamps from YouTube Videos**

In this tutorial, we will explore how to use Assembly AI to generate time stamps from YouTube videos. We will start by creating an API key and setting it up as a secret in our code.

Once we have our API key, we can create a new secret called "AI Key" and paste the value into our code. This will allow us to use Assembly AI's functionality to generate time stamps.

To import the necessary code, we will need to add the following block of code:

```python

from assemblyai import Transcriber

# Set up Assembly AI API key

assembly_ai_key = "YOUR_API_KEY_HERE"

# Create a new secret called 'AI Key'

secret = {

"name": "AI Key",

"value": assembly_ai_key,

}

# Import the necessary code

import assemblyai as ai

```

**Transcribing Audio and Generating Transcript**

First, we need to transcribe our audio file using Assembly AI's `transcriber` function. We will save the transcript in a variable called `transcript`.

Here is an example of how to do this:

```python

# Transcribe the audio file using Assembly AI's transcriber function

transcriber = ai.Transcriber()

audio_file = "path/to/audio/file.mp3"

transcript = transcriber.transcribe(audio_file)

```

**Combining Transcript into a Corpus Text**

Next, we need to combine our transcript into a single corpus text. We will store this in a variable called `paragraphs`.

Here is an example of how to do this:

```python

# Combine the transcript into a single corpus text

corpus_text = ""

for sentence in transcript.split("."):

corpus_text += sentence + " "

```

**Generating Time Stamps**

Now that we have our corpus text, we can start generating time stamps for each paragraph. We will use a loop to iterate through each paragraph and generate key topics.

Here is an example of how to do this:

```python

# Generate time stamps for each paragraph

time_stamps = []

for i in range(0, len(paragraphs), 5):

paragraph = paragraphs[i:i+5]

for j in range(len(paragraph)):

topic = ai.TopicGenerator().generate_topic(paragraph[j])

start_time = ai.TimeStamp.generate_start_time(j*60) # assuming each minute has 60 seconds

end_time = ai.TimeStamp.generate_end_time(start_time, len(paragraph[j]))

time_stamps.append((start_time, end_time, topic))

```

**Running the Script**

Once we have generated our time stamps, we can run the script to see the results.

The final output will be a list of time stamps with corresponding key topics. The time stamps will be in the format `MM:SS`, and the key topics will be based on the transcription of each paragraph.

**Example Output**

Here is an example of what the output might look like:

```

[("00:13:14", "01:14:15"), ("01:16:05", "02:17:06")]

[( "00:10:35", "Trust Your Intuition"), ("01:11:20", "Perseverance") ]

...

```

Note that the actual output will depend on the transcription of your audio file and the topic generator's ability to identify key topics.

**Conclusion**

In this tutorial, we used Assembly AI to generate time stamps from a YouTube video. We transcribed the audio file using Assembly AI's `transcriber` function, combined the transcript into a single corpus text, and generated time stamps for each paragraph using a loop. The final output was a list of time stamps with corresponding key topics.

We hope this tutorial helps you understand how to use Assembly AI to generate time stamps from YouTube videos. If you have any questions or need further assistance, please don't hesitate to ask.

"WEBVTTKind: captionsLanguage: enwouldn't it be great if there are timestamps for every single YouTube video that you're watching so that you could have easy access to specific chapters in the video well I know that currently some videos do have time stamps for you to hop around the video however there are many especially longer podcast Style video where there are no time stamps for you to hop around with and so in this video you're going to learn how you could generate your own typ STS for any YouTube video and we're going to do that using assembly Ai and anthropic which is built in and so without further Ado let's dive in all right and so we're going to generate time stamp for any YouTube videos using assembly Ai and so this could also be a zoom call that you have recorded for your meetings and so feel free to use this for any other audio content that you have video with audio but also please be extra careful that you have Authority or the copyright in order to do so so let's go ahead and install the prerequisite libraries here we're going to install ffmpeg okay I did I've already done so already so all of the code cells here has already been run so for the sake of tutorial let's rerun it again so that you know how it looks like so here we're going to download the YouTube downloader library and then we're going to install assembly AI python Library we then will import the API for assembly AI here into our environment so for safekeeping I've included the assembly AI key along with several other API keys that I have right inside the collap notebook now that it's already an environment we're ready to proceed in downloading the YouTube video so here is the URL of the video that we're going to download so we're going to use Steve Jobs very Infamous commencement address here and it's about 15 minutes long and you do see that there are already time stamps in this video but for the sake of Education we're going to use this as an example so feel free to use other longer form content video content as part of your tutorial and so you could replace the URL here okay so this is the custom function that we've created in a prior tutorial on the data Professor YouTube channel in this video so feel free to watch this and I'll provide you the link to this also in the video description so if you haven't already go ahead and watch this video so that you'll know how you could create your own YouTube AI assistant uh in Python and so yeah before proceeding further if you don't yet have an assembly AI key which which I already have one and I already put it into the sequence management here um go ahead to assembly ai.com and then you can sign up by using your own credentials so I'm logging in here and yeah so your API key is conveniently located right in the dashboard you could just click copy API key and then you have access to that um so I already have some funds available here so kudos to the assembly AI team for giving me credits to use in the tutorial so let's head back to the tutorial here and then once you have the API key you could create your own secret here add a new secret and and then you could say AI key and then paste the value in here and then you're all set and then to import it you'll need this following block of code here followed by the identifier of your assembly AI key all right and so after running this you'll be able to have a MP3 file of the YouTube video ready for you and now we're going to proceed to generating the time stamps here so we've already created two separate tasks that we're going to do so let's have a look first we're going to take the audio file that we have which is the generated MP3 file we're going to transcribe the audio file so for that we're using a assembly ai's transcriber function and then we're going to save it into the transcript variable and then you'll see that we're using transcriber transcribe method from assembly Ai and then the audio file is the MP3 file as the input argument here and once we have the transcript ready we're going to generate the entire Corpus of the text and then assign it to the paragraphs variable so and all of the text will be in the paragraphs variable then we're going to iterate through each paragraph from the entire Text corpus and then for each paragraph we're going to have generate a few Topics in there and then for each topic we're going to have an e Tim stamp so finally we're going to generate the final Tim stamp where there are the timestamp followed by the key topic name um and so this will happen iteratively for all of the paragraphs in the video or audio so to say so let's run it it should take a while because first it's generating the transcript and then it's combining it into a single Corpus text and then this is only the first part right and once we have this first part we're then going to generate the final time stamp let's give us some time okay and it's finished let's have a look at the combined paragraphs here so this is the combined paragraph so you're going to see that for the entire content here we split it up into paragraphs and then for each paragraph We have the essentially the time stamp you see the start and the ending um values here and then we're going to generate the final time stamp where we're telling it explicitly that we want to have it in the minute seconds format and that we don't we don't want any you know notes or any generated description of the content that the model will create so on prior runs it is giving me notes or based on the given transcript it is providing the f key topics so uh we don't want any of that so we we specify that into the prompt and so we should be able to get purely the the time stamp along with the key topics so let's run it let's give it a few moments here so you're seeing here now that we have already the generated paragraph or the the Text corpus we're essentially using for Loop here iterating through the entire Corpus text and we're iterating through each paragraph right and so for each paragraph we're going to generate key topics along with the time stamp which you'll see here so you notice that there are some blank space in between right so the blank space is here is just going to show you that there are paragraphs of text so this is the first paragraph This is the second paragraph third paragraph fourth paragraph and for each paragraph you're going to see the it's generating roughly five key topics with the corresponding Tim stamp and so here we go the video is about 13 14 15 minutes long right okay and let's have a look at minute number five 16 seconds in it's about trusting your intuition let's have a look there 516 now connect in your future you have to trust in something your gut Destiny Life Karma whatever right so it's pretty much trusting your intuition right so it's very accurate here let's see something about perseverance 851 BL so keep looking don't settle okay perseverance right so yeah there you have it you could input a longer podcast and then you'll get your own timestamp so that you could you know essentially hop to the specific topics that you're interested in and yeah let me know in the comment section down below how you're using this particular python workflow to become more productive and so I'd love to hear them all and yeah drop them all in the comment section thank you for watching till the end of the video if you reach this far please drop a fire Emoji so that we know that you the real one and as always please smash the like button subscribe to the channel and also turn on notifications so that you'll be notified of the next video and as always the best way to learn is to do and until next timewouldn't it be great if there are timestamps for every single YouTube video that you're watching so that you could have easy access to specific chapters in the video well I know that currently some videos do have time stamps for you to hop around the video however there are many especially longer podcast Style video where there are no time stamps for you to hop around with and so in this video you're going to learn how you could generate your own typ STS for any YouTube video and we're going to do that using assembly Ai and anthropic which is built in and so without further Ado let's dive in all right and so we're going to generate time stamp for any YouTube videos using assembly Ai and so this could also be a zoom call that you have recorded for your meetings and so feel free to use this for any other audio content that you have video with audio but also please be extra careful that you have Authority or the copyright in order to do so so let's go ahead and install the prerequisite libraries here we're going to install ffmpeg okay I did I've already done so already so all of the code cells here has already been run so for the sake of tutorial let's rerun it again so that you know how it looks like so here we're going to download the YouTube downloader library and then we're going to install assembly AI python Library we then will import the API for assembly AI here into our environment so for safekeeping I've included the assembly AI key along with several other API keys that I have right inside the collap notebook now that it's already an environment we're ready to proceed in downloading the YouTube video so here is the URL of the video that we're going to download so we're going to use Steve Jobs very Infamous commencement address here and it's about 15 minutes long and you do see that there are already time stamps in this video but for the sake of Education we're going to use this as an example so feel free to use other longer form content video content as part of your tutorial and so you could replace the URL here okay so this is the custom function that we've created in a prior tutorial on the data Professor YouTube channel in this video so feel free to watch this and I'll provide you the link to this also in the video description so if you haven't already go ahead and watch this video so that you'll know how you could create your own YouTube AI assistant uh in Python and so yeah before proceeding further if you don't yet have an assembly AI key which which I already have one and I already put it into the sequence management here um go ahead to assembly ai.com and then you can sign up by using your own credentials so I'm logging in here and yeah so your API key is conveniently located right in the dashboard you could just click copy API key and then you have access to that um so I already have some funds available here so kudos to the assembly AI team for giving me credits to use in the tutorial so let's head back to the tutorial here and then once you have the API key you could create your own secret here add a new secret and and then you could say AI key and then paste the value in here and then you're all set and then to import it you'll need this following block of code here followed by the identifier of your assembly AI key all right and so after running this you'll be able to have a MP3 file of the YouTube video ready for you and now we're going to proceed to generating the time stamps here so we've already created two separate tasks that we're going to do so let's have a look first we're going to take the audio file that we have which is the generated MP3 file we're going to transcribe the audio file so for that we're using a assembly ai's transcriber function and then we're going to save it into the transcript variable and then you'll see that we're using transcriber transcribe method from assembly Ai and then the audio file is the MP3 file as the input argument here and once we have the transcript ready we're going to generate the entire Corpus of the text and then assign it to the paragraphs variable so and all of the text will be in the paragraphs variable then we're going to iterate through each paragraph from the entire Text corpus and then for each paragraph we're going to have generate a few Topics in there and then for each topic we're going to have an e Tim stamp so finally we're going to generate the final Tim stamp where there are the timestamp followed by the key topic name um and so this will happen iteratively for all of the paragraphs in the video or audio so to say so let's run it it should take a while because first it's generating the transcript and then it's combining it into a single Corpus text and then this is only the first part right and once we have this first part we're then going to generate the final time stamp let's give us some time okay and it's finished let's have a look at the combined paragraphs here so this is the combined paragraph so you're going to see that for the entire content here we split it up into paragraphs and then for each paragraph We have the essentially the time stamp you see the start and the ending um values here and then we're going to generate the final time stamp where we're telling it explicitly that we want to have it in the minute seconds format and that we don't we don't want any you know notes or any generated description of the content that the model will create so on prior runs it is giving me notes or based on the given transcript it is providing the f key topics so uh we don't want any of that so we we specify that into the prompt and so we should be able to get purely the the time stamp along with the key topics so let's run it let's give it a few moments here so you're seeing here now that we have already the generated paragraph or the the Text corpus we're essentially using for Loop here iterating through the entire Corpus text and we're iterating through each paragraph right and so for each paragraph we're going to generate key topics along with the time stamp which you'll see here so you notice that there are some blank space in between right so the blank space is here is just going to show you that there are paragraphs of text so this is the first paragraph This is the second paragraph third paragraph fourth paragraph and for each paragraph you're going to see the it's generating roughly five key topics with the corresponding Tim stamp and so here we go the video is about 13 14 15 minutes long right okay and let's have a look at minute number five 16 seconds in it's about trusting your intuition let's have a look there 516 now connect in your future you have to trust in something your gut Destiny Life Karma whatever right so it's pretty much trusting your intuition right so it's very accurate here let's see something about perseverance 851 BL so keep looking don't settle okay perseverance right so yeah there you have it you could input a longer podcast and then you'll get your own timestamp so that you could you know essentially hop to the specific topics that you're interested in and yeah let me know in the comment section down below how you're using this particular python workflow to become more productive and so I'd love to hear them all and yeah drop them all in the comment section thank you for watching till the end of the video if you reach this far please drop a fire Emoji so that we know that you the real one and as always please smash the like button subscribe to the channel and also turn on notifications so that you'll be notified of the next video and as always the best way to learn is to do and until next time\n"