A few weeks ago I posted about how one can create code leveraging OpenAIโs chatGPT to obtain a summary of the content in all your new emails. OpenAI can be utlised in various ways to create useful tools that enhance productivity.
ChatGPT, in fact, not only answers questions in multiple languages but can also transcribe audio from a lecture into text. The Langchain Python package, which can be freely installed, includes built-in libraries that allow a user to download the audio from a YouTube video lecture and extract the text. This can be particularly useful for many podcasts when one lacks the time to watch full episodes that can be 2-3 hours long and would prefer to simply read the transcripts.
The only requirement, of course, is to have an OpenAI account with an OpenAI key. A one-hour long podcast should cost less than one dollar, making it affordable for private use. This and more can be learned by taking the DeepLearning.ai course Langchain chat with your data.
In fact, there also exists a speech_recognition library in python that would allow us to do the same for free, but it requires slighly more work because it only accepts audio files of limited length (you need to split it and to transcribe a piece at a time). In addition, by using Langchain, the punctuation is actually more accurate, enhancing the overall experience.
For anyone interested, I have put together some very simple code that, assuming you have created your own OpenAI key, will allow you to enter any YouTube video lecture link and obtain the transcripts of that lecture on your computer drive as a text file.
import os
import openai
from langchain.document_loaders.generic import GenericLoader
from langchain.document_loaders.parsers import OpenAIWhisperParser
from langchain.document_loaders.blob_loaders.youtube_audio import YoutubeAudioLoader
def main(url, file_path):
load_openai_key()
#This is the code to load a YouTube Video and save the audio locally
loader = GenericLoader(
YoutubeAudioLoader([url], os.path.dirname(file_path)),
OpenAIWhisperParser()
)
#This is the code to transcribe the audio into text and save it a file
docs = loader.load()
with open(file_path, 'w', encoding='utf-8') as f:
for item in docs:
# write each item
f.write(item.page_content)
print('Done')
return docs
def load_openai_key():
keyfile = "path_to_openai_key" #modify as needed
with open(keyfile, 'r') as f:
key = f.read().strip()
openai.api_key = key
os.environ["OPENAI_API_KEY"] = key
if __name__ == "__main__":
youtube_link = "link_to_video" #modify as needed
file_path = "path_to_transcripts.txt" #modify as needed
main(youtube_link, file_path)
Letโs say you want to watch the following short video:
Now, if you prefer, you can simply read the following transcripts instead:
The worst possible things in the morning to set their day up for failure, what would they be? Wake up and stay in bed. There are good reasons to stay in bed in the morning, but once those are completed, then staying in bed, curtains drawn, just passively scrolling on social media. There are neurobiological data showing that when you are upright, you actually are stimulating this area of the brain called locus coeruleus, whereas when you recline, you actually are less alert. And the postural stuff is really bad too. This is so common now, the C-shaped human thing, that it almost feels strange to be upright. I would say in bed, so people are on their phone, they're not getting enough light, or they're trying to get the sunlight through the window. Terrible. They're drinking coffee too early in the day, but it's mostly about this sort of randomization of activities. Sort of making a cup of coffee while texting. Then they're scattering that in with like a little bit of work, but then something hits that's stressful and they're diverting their attention. They're sort of building in this attention deficit-like disorder. They're not being deliberate or intentional with the things that they're doing, they're just allowing the morning to kind of come and take them wherever the wind blows. That's right.
This is it, a simple useful tool to, hopefully, enhance your productivity.