diff --git a/config.ini b/config.ini index 62699b42..ec865a29 100644 --- a/config.ini +++ b/config.ini @@ -4,7 +4,7 @@ KMP_DUPLICATE_LIB_OK=TRUE # Export OpenAI API Key OPENAI_APIKEY= # Export Whisper Model Size -WHISPER_MODEL_SIZE=medium +WHISPER_MODEL_SIZE=tiny WHISPER_REAL_TIME_MODEL_SIZE=tiny # AWS config AWS_ACCESS_KEY=***REMOVED*** diff --git a/requirements.txt b/requirements.txt index 490ee05d..fdb18eb2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -48,4 +48,5 @@ pandas jupyter seaborn matplotlib -termcolor \ No newline at end of file +termcolor +https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz diff --git a/text_utilities.py b/text_utilities.py index 1ff0a70c..be022918 100644 --- a/text_utilities.py +++ b/text_utilities.py @@ -20,7 +20,6 @@ def preprocess_sentence(sentence): def compute_similarity(sent1, sent2): tfidf_vectorizer = TfidfVectorizer() - print("semt1", sent1, sent2) if sent1 is not None and sent2 is not None: tfidf_matrix = tfidf_vectorizer.fit_transform([sent1, sent2]) return cosine_similarity(tfidf_matrix[0], tfidf_matrix[1])[0][0] diff --git a/whisjax.py b/whisjax.py index e0cce47f..d4fd7c5a 100644 --- a/whisjax.py +++ b/whisjax.py @@ -16,7 +16,7 @@ import subprocess import re import tempfile from loguru import logger -from pytube import YouTube +import yt_dlp as youtube_dl from urllib.parse import urlparse from whisper_jax import FlaxWhisperPipline @@ -73,9 +73,21 @@ def main(): # It will be saved to the current directory. logger.info("Downloading YouTube video at url: " + args.location) - youtube = YouTube(args.location) - media_file = youtube.streams.filter(progressive=True, file_extension='mp4').order_by( - 'resolution').asc().first().download() + # Create options for the download + ydl_opts = { + 'format': 'bestaudio/best', + 'postprocessors': [{ + 'key': 'FFmpegExtractAudio', + 'preferredcodec': 'mp3', + 'preferredquality': '192', + }], + 'outtmpl': 'audio', # Specify the output file path and name + } + + # Download the audio + with youtube_dl.YoutubeDL(ydl_opts) as ydl: + ydl.download([args.location]) + media_file = "audio.mp3" logger.info("Saved downloaded YouTube video to: " + media_file) else: @@ -96,16 +108,19 @@ def main(): quit() # Handle video - try: - video = moviepy.editor.VideoFileClip(media_file) - audio_filename = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False).name - video.audio.write_audiofile(audio_filename, logger=None) - logger.info(f"Extracting audio to: {audio_filename}") - # Handle audio only file - except: - audio = moviepy.editor.AudioFileClip(media_file) - audio_filename = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False).name - audio.write_audiofile(audio_filename, logger=None) + if not media_file.endswith(".mp3"): + try: + video = moviepy.editor.VideoFileClip(media_file) + audio_filename = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False).name + video.audio.write_audiofile(audio_filename, logger=None) + logger.info(f"Extracting audio to: {audio_filename}") + # Handle audio only file + except: + audio = moviepy.editor.AudioFileClip(media_file) + audio_filename = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False).name + audio.write_audiofile(audio_filename, logger=None) + else: + audio_filename = media_file logger.info("Finished extracting audio") diff --git a/youtube.py b/youtube.py new file mode 100644 index 00000000..e69de29b