Skip to content

Instantly share code, notes, and snippets.

@svpino
Created August 1, 2023 12:58
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save svpino/fc64db771566d04a10accf59ae070c93 to your computer and use it in GitHub Desktop.
Save svpino/fc64db771566d04a10accf59ae070c93 to your computer and use it in GitHub Desktop.
import os
import assemblyai as aai
from pytube import YouTube
aai.settings.api_key = "INSERT YOUR API KEY HERE"
youtube_url = "https://www.youtube.com/watch?v=f94wKh70cOY"
# Let's download the YouTube video
youtube = YouTube(youtube_url)
audio = youtube.streams.filter(only_audio=True).first()
filename = os.path.basename(audio.download())
# We can now transcribe it
transcriber = aai.Transcriber()
transcript = transcriber.transcribe(filename)
print(transcript.text)
# This will summarize the video
summary = transcript.lemur.summarize(
context="A magician performing a magic trick"
)
print(summary.response)
# Now we can ask questions about the video
questions = [
aai.LemurQuestion(question="What is the name of the magician?"),
aai.LemurQuestion(question="What are the names of the participants?"),
aai.LemurQuestion(question="What is the magic trick about?"),
]
answers = transcript.lemur.question(questions)
for answer in answers.response:
print(f"Question: {answer.question}")
print(f"Answer: {answer.answer}")
print()
@dwivedys
Copy link

dwivedys commented Aug 3, 2023

Will try this out. Can I do ‘pip install’ to install the libraries?

@svpino
Copy link
Author

svpino commented Aug 3, 2023

Yes, you need this:

pip install assemblyai pytube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment